[英]File upload to web using PHP server, not working
我在127.0.0.1:8080
上運行用於測試目的的php服務器,並且嘗試使用save2web.php
將圖像保存到“ web”:
if (isset($_FILES)){
//put parameters in variables
$filename = $_FILES['file']['name'];
$fileTempName = $_FILES['file']['tmp_name'];
$fileType = $_FILES['file']['type'];
$fileSize = $_FILES['file']['size'];
$fileError = $_FILES['file']['error'];
//if the file is a JPG and under 400K, proceed:
if (($fileType == "image/jpeg") && ($fileSize < 400000)){
//if there's a file error, print it:
if ( $fileError > 0){
echo "Return Code" . $fileError . "<br />";
}
//if there's no error, print some HTML about the file:
else {
echo "Upload: " . $fileName . "<br />";
echo "Type: " . $fileType . "<br />";
echo "Size: " . ($fileSize/1024) . " Kb<br />";
echo "Temp file: " . $fileTempName . "<br />";
//if the file already exists,
//delete the previous version:
if (file_exists($fileName)){
unlink($fileName);
}
//move the file from the temp location to
//this directory:
move_uploaded_file($fileTempName, $fileName);
echo "Uploaded file stored as: ".$filename;
}
}
//if the file is not a jpg or too big, say so:
else{
echo "File is not a JPEG or too big.";
}
}
?>
<html>
<body>
<form action="save2web.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Upload" />
</form>
</body>
</html>
但是,當我在瀏覽器上運行腳本時,得到:
Upload:
Type: image/jpeg
Size: 45.728515625 Kb
Temp file: /private/var/tmp/phpEgyvKC
Warning: move_uploaded_file(): Filename cannot be empty in /Users/me/Documents/CODE/Processing/sketches_3/sketches/apps/NetworkedCat_ImageCaptureUpload/save2web.php on line 31
Warning: move_uploaded_file(): Unable to move '/private/var/tmp/phpEgyvKC' to '' in /Users/me/Documents/CODE/Processing/sketches_3/sketches/apps/NetworkedCat_ImageCaptureUpload/save2web.php on line 31
存儲為:Peti2.jpg
“第31行”是move_uploaded_file()
這似乎不是權限問題,因為我已將/private/var/tmp
以及目標文件夾上的chmod 777
權限更改為
我想念什么?
目的地不是目錄,而是文件;
在所有代碼之前,設置:
$path='img.jpg'
然后:
move_uploaded_file($fileTempName, $path);
圖片將在那里上傳; 如果path
上的圖像名稱相同,則將替換文件。
設置您要上傳文件的路徑
$ path ='您的文件夾路徑';
move_uploaded_file($fileTempName, $path.$fileName);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.