上传图片方向不对 php,php-上传图片时出现错误,没有这样的路径或目录
美好的一天,我一直在學(xué)習(xí)教程,并且為使該腳本正常工作付出了很大的努力,我設(shè)法解決了許多問題,但是我遇到的一個(gè)經(jīng)常出現(xiàn)的問題是:
第93行的/home/xxxxxxx/public_html/regForm.php中沒有此類文件或目錄
我要完成的工作是讓用戶在注冊時(shí)將個(gè)人資料圖片上傳到我的實(shí)時(shí)服務(wù)器/網(wǎng)站,這是我的表格和以下代碼的一部分:
如果經(jīng)驗(yàn)豐富的用戶可以進(jìn)行掃描并提前告訴我我要去哪里,我將不勝感激.
:
:
Upload Picture:
上傳腳本
$file_upload="true";
$file_up_size=$_FILES['file_up']['size'];
echo $_FILES['file_up']['name'];
if ($_FILES['file_up']['size']>250000){
$msg=$msg."Your uploaded file size is more than 250KB
so please reduce the file size and then upload.
";
$file_upload="false";
}
if (!($_FILES['file_up']['type'] =="image/jpeg" OR $_FILES['file_up']['type'] =="image/gif"))
{
$msg=$msg."Your uploaded file must be of JPG or GIF. Other file types are not allowed
";
$file_upload="false";
}
$file_name=$_FILES['file_up']['name'];
if($file_upload=="true"){
$ftp_server = "xxxxxx";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$ftp_username='xxxxxx';
$ftp_userpass='xxxxxx';
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);
$file = $file_name;
// upload file
if (ftp_put($ftp_conn, "public_html/img/userPics", $file, FTP_ASCII)) //here is the problem with the path I suspect
{
echo "Successfully uploaded $file.";
}
else
{
echo "Error uploading $file.";
}
// close connection
ftp_close($ftp_conn);
}
解決方法:
處理圖像時(shí),需要使用二進(jìn)制格式.
FTP_BINARY而不是FTP_ASCII.
按照手冊:
確保路徑正確.這可能與不同的服務(wù)器不同.
您還需要在此處加上斜杠:
public_html/img/userPics/
^
否則,您的系統(tǒng)將其解釋為:
userPicsIMAGE.JPG,而不是預(yù)期的userPics / IMAGE.JPG
但是,您可能需要嘗試一下路徑本身. FTP有點(diǎn)棘手.
即:
> / home / xxxxxxx / public_html / userPics /
> img /用戶圖片/
> ../img/userPics/
取決于文件的執(zhí)行區(qū)域.
Root > ftp_file.php
-img
-userPics
該文件夾還需要具有適當(dāng)?shù)臋?quán)限才能寫入.
>通常為755.
如果您的系統(tǒng)尚未設(shè)置為捕獲并顯示錯(cuò)誤/通知,請使用錯(cuò)誤報(bào)告:
FTP手冊中的一個(gè)示例:
ftp_chdir($conn, '/www/site/');
ftp_put($conn,'file.html', 'c:/wamp/www/site/file.html', FTP_BINARY );
?>
但是,另一件事是使用“ true”和“ false”.您最有可能想要檢查真實(shí)性
$file_upload=true;
而不是字符串文字$file_upload =“ true”;
同樣的事情
if($file_upload=="true")
至
if($file_upload==true)
和$file_upload =“ false”;檢查虛假
到$file_upload = false;
閱讀此手冊:
This is the simplest type. A boolean expresses a truth value. It can be either TRUE or FALSE.
try {
$con = ftp_connect($server);
if (false === $con) {
throw new Exception('Unable to connect');
}
$loggedIn = ftp_login($con, $username, $password);
if (true === $loggedIn) {
echo 'Success!';
} else {
throw new Exception('Unable to log in');
}
print_r(ftp_nlist($con, "."));
ftp_close($con);
} catch (Exception $e) {
echo "Failure: " . $e->getMessage();
}
命名約定:
我還需要注意的是,在LINUX上,如果您的文件夾名稱使用小寫字母,則userPics與userpics不同.
與Windows不同,它不區(qū)分大小寫.
標(biāo)簽:forms,php
來源: https://codeday.me/bug/20191119/2038749.html
總結(jié)
以上是生活随笔為你收集整理的上传图片方向不对 php,php-上传图片时出现错误,没有这样的路径或目录的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: oracle取本月最后一天是星期几_or
- 下一篇: 网购的笔记本电脑如何验货笔记本电脑怎样验