2015-12-22 74 views
0

首先我想爲這個問題道歉,因爲我知道已經有很多人問這個問題了。但我搜索的所有答案都沒有解決我的問題。所以希望你考慮這個問題並幫助我解決這個問題。在上傳php文件時出現錯誤(圖片)

所以基本上我試圖上傳的圖片文件,當我提交,錯誤彈出:

Warning: move_uploaded_file(./images/jarvs.jpg): failed to open stream:

Warning: move_uploaded_file(): Unable to move 'C:\wamp\tmp\phpA25F.tmp' to './images/jarvs.jpg'

我真的不明白的錯誤,但我知道,錯誤當我嘗試從圖像的路徑傳輸圖像,並將其發送到我的目標文件夾(目標路徑)時發生的

因此繼承我的代碼:

HTML: <input id="profimagefile" name="profileimage" class="input-file" type="file">

PHP:

$targetPath = "images/"; 
$targetPath = $targetPath.basename($_FILES['profileimage']['name']); 

//name of the file 
$img = $_FILES['profileimage']['name']; 
$size = $_FILES['profileimage']['size']; 
$type = $_FILES['profileimage']['type']; 

if(move_uploaded_file($_FILES['profileimage']['tmp_name'], $targetPath)) 
{ 
$queryupload = "INSERT INTO images_profile (image_name, image_path, date_uploaded, emailAddress) 
    VALUES ('$img', '$targetPath','$registerDate', '$email')"; 

mysqli_query($conn, $queryupload); 
echo "The file ". basename($_FILES['profileimage']['name']). " has been uploaded." . "<br/>"; 
} 
else { 
echo "Sorry, there was a problem uploading your file." . "<br/>"; 
} 

不介意數據庫的接入,它只是過程的一部分後的圖像已經搬到我TARGETPATH。 感謝你回答

+0

你給文件夾的權限 – rahul

+0

有請檢查「images /」文件夾的權限 –

+0

有什麼權限?我不明白。 –

回答

0

試試這個..

$targetPath = "images/"; 
//create folder if not exist 
if(!is_dir($targetPath)){ 
    if(!mkdir($targetPath, 0777, true)){ 
     die('Failed to create folder.'); 
    } 
} 
//set folder's permissions writale and executable 
chmod($targetPath, 0777); 
$targetPath = $targetPath.basename($_FILES['profileimage']['name']); 

//name of the file 
$img = $_FILES['profileimage']['name']; 
$size = $_FILES['profileimage']['size']; 
$type = $_FILES['profileimage']['type']; 

if(move_uploaded_file($_FILES['profileimage']['tmp_name'], $targetPath)) 
{ 
$queryupload = "INSERT INTO images_profile (image_name, image_path, date_uploaded, emailAddress) 
    VALUES ('$img', '$targetPath','$registerDate', '$email')"; 

mysqli_query($conn, $queryupload); 
echo "The file ". basename($_FILES['profileimage']['name']). " has been uploaded." . "<br/>"; 
} 
else { 
echo "Sorry, there was a problem uploading your file." . "<br/>"; 
} 
+0

感謝,它的工作 –

+0

我現在明白爲什麼它給了我一個錯誤,因爲實際上我的圖像文件夾不在我的php文件所在的同一目錄中 我的圖像文件夾位於:「public/images「 while my php file is in:」public/php/saveimage.php「 –

0

試試這個::

HTML

<form enctype="multipart/form-data> 
<input id="profimagefile" name="profileimage" class="input-file" type="file"> 
</form> 

PHP

if(file_exists(__DIR__."/images"){ 
$targetPath = __DIR__."/images/"; 
$targetPath .= $_FILES['profileimage']['name']; 

if(move_uploaded_file($_FILES['profileimage']['tmp_name'], $targetPath)){ 
echo "Upload success"; 
} else { 
echo "Upload failed"; 
} 
} else { 
    echo "Dir images not found"; 
} 
+0

nope,它給我帶來了其他的聲明,沒有去file_exists –

+0

在你的其他迴音錯誤號碼中加入這一行:「。$ _ FILES ['profileimage'] [」error「] ; –

+0

你是否收到任何文件上傳的錯誤代碼?如果文件完全上傳$ _FILES ['profileimage'] [「error」]將爲零 –