代碼如下:
upload.php
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "
";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "
";
echo "Type: " . $_FILES["file"]["type"] . "
";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb
";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "
";
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
?>
運行結果:
Upload: jdk-6u34-windows-x64.exe
Type: application/octet-stream
Size: 61154.484375 Kb
Temp file: F:\xampp\tmp\phpCB11.tmp
Warning: move_uploaded_file(upload/jdk-6u34-windows-x64.exe): failed to open stream: No such file or directory in F:\xampp\htdocs\test\qwe.php on line 26
Warning: move_uploaded_file(): Unable to move 'F:\xampp\tmp\phpCB11.tmp' to 'upload/jdk-6u34-windows-x64.exe' in F:\xampp\htdocs\test\qwe.php on line 26
Stored in: upload/jdk-6u34-windows-x64.exe
糾結好久了,平台環境是windows平台下安裝XAMPPIntegration Environment
望高手解答,並且想知道是為什麼……
回複討論(解決方案)
目錄 upload 不存在
可能原因:
1.路徑不對。
2.檔案夾沒有許可權。
加 dirname(__FILE__) 看看。
if (file_exists(dirname(__FILE__)."/upload/" . $_FILES["file"]["name"]))
failed to open stream: No such file or directory
哥們兒 你解決了嗎?我在UBUNTU下搭建LAMP環境也出現了一樣的問題 找不到上傳的檔案啊