2017-03-08 73 views
0

此代碼不會打印上傳圖像的臨時名稱,也不會上載任何圖片到我的照片文件夾中。但打印圖像名稱。它正確地工作其他計算機。哪裏有問題?請幫幫我。我使用的PHP版本5.6.20使用PHP的圖像上傳Mysql

<!DOCTYPE html> 
<html> 
<head> 
    <title>Image Upload</title> 
</head> 

<body> 
<?php 

if ($_SERVER["REQUEST_METHOD"] == "POST") 
{ 

    $destination = "Photo/".$_FILES['image']['name']; 
    $filename = $_FILES['image']['tmp_name']; 
    echo $destination; 
    echo "<br/>"; 
    echo $filename; 
    echo "<br/>"; 

    if (file_exists($destination)) 

echo "Sorry, file already exists."; 

else 
    move_uploaded_file($filename, $destination); 
    $name=$_FILES['image']['name']; 
    $tmp_name=$_FILES['image']['tmp_name']; 

    echo $tmp_name; 
} 


?> 

<form method="POST" enctype="multipart/form-data"> 

<table> 

<tr> 
    <td>Choose Image</td> 
    <td><input type="file" name="image"/> </td> 
</tr> 

<tr> 
    <td>Description:</td> 
    <td><textarea name="Description" rows="4" cols="40"/></textarea></td> 
</tr> 

<tr> 
    <td></td> 

    <td> <input type="submit" name="submit_image" value="Submit"></td> 
</tr> 
</table> 
</form> 

</body> 
</html> 

回答

1
<!DOCTYPE html> 
<html> 
<head> 
    <title>Image Upload</title> 
</head> 

<body> 
<?php 

if(isset($_POST['submit_image'])) 
{ 

    $destination = "Photo/".$_FILES['image']['name']; 
    $filename = $_FILES['image']['tmp_name']; 
    echo $destination; 
    echo "<br/>"; 
    echo $filename; 
    echo "<br/>"; 

    if (file_exists($destination)) 

echo "Sorry, file already exists."; 

else 
    move_uploaded_file($filename, $destination); 
    $name=$_FILES['image']['name']; 
    $tmp_name=$_FILES['image']['tmp_name']; 

    echo $tmp_name; 
} 


?> 

<form method="POST" enctype="multipart/form-data"> 

<table> 

<tr> 
    <td>Choose Image</td> 
    <td><input type="file" name="image"/> </td> 
</tr> 

<tr> 
    <td>Description:</td> 
    <td><textarea name="Description" rows="4" cols="40"/></textarea></td> 
</tr> 

<tr> 
    <td></td> 

    <td> <input type="submit" name="submit_image" value="Submit"></td> 
</tr> 
</table> 
</form> 

</body> 
</html> 

我想這個代碼是爲我工作。請給我看照片文件夾的寫入權限 我認爲它會爲你工作。

+1

完成,但不幸的是它不工作。 – Ramzan

+0

發生了什麼問題 –

+0

在我的代碼中,我打印上傳的圖像名稱和該圖像的臨時名稱,並將該圖像上傳到文件夾名稱'照片'中。但問題是它只打印此圖像的名稱,但不打印temp_name,並沒有在我的照片文件夾中上傳任何圖像 – Ramzan

0

我認爲這部分寫正確這樣既解決

if (file_exists($destination)){ 
echo "Sorry, file already exists."; 
}else{ 
    move_uploaded_file($filename, $destination); 
    $name=$_FILES['image']['name']; 
    $tmp_name=$_FILES['image']['tmp_name']; 
    echo $tmp_name; 
} 
+0

完成但不工作,我不知道爲什麼它沒有在我的電腦中打印temp_name。但它適用於其他計算機 – Ramzan

+0

不工作它劑量意味着你給我的問題錯誤的審查,就像沒有人會回答 –

+0

親愛的我不給錯誤的審查。你正試圖解決我的問題,爲什麼我給你的評論錯誤的審查? – Ramzan

1

你的代碼工作正常,請檢查'照片/'文件夾權限和tmp文件夾路徑。例如:D:\ xampp \ tmp \ phpDCD9.tmp。

+0

嘗試過但不能在這裏工作 – Ramzan

+0

嘗試把error_reporting(0);腳本和檢查,什麼類型的錯誤是打印的error_reporting(0)之後獲得 –

+0

它顯示輸出22527.裏面我不understant這個 – Ramzan

1

您的代碼在我的機器上完美工作。我想你可能想檢查存儲上傳文件的目錄名稱Photo。檢查你的目的地文件夾名稱你的編碼和定義文件夾名稱你的項目是相同的。 請發送您的errorwarning消息,以便它很容易幫助。

+0

我覺得一切都很好。我告訴過它可以使用其他電腦,但不能使用我的電腦。拉屎 – Ramzan