[英]PHP's move_uploaded_file error: Permission denied on Mac
我是PHP新手,似乎無法將文件上傳到Web服務器。 我已將自己設為一個簡單的表單,並擁有一個PHP文件來控制上傳,但是每次運行代碼時,都會出現錯誤。 這是代碼:
<?php
$name = $_FILES['upload']['name'];
$temp = $_FILES['upload']['tmp_name'];
$error = $_FILES['upload']['error'];
if ($error = 0) {
move_uploaded_file($temp, "images/" . $name);
echo 'Success';
} else {
die ('$error');
}
?>
這是錯誤:
Warning: move_uploaded_file(images/macbook.jpg): failed to open stream: No such file or directory in /Library/WebServer/Documents/doc/ch07/upload_check.php on line 7
Warning: move_uploaded_file(): Unable to move '/private/var/tmp/phpuMC0td' to 'images/macbook.jpg' in /Library/WebServer/Documents/doc/ch07/upload_check.php on line 7
提前致謝!
錯誤分配vs評估if ($error = 0)
應該是if ($error == 0)
名稱來自基本名稱。 還要聲明目標。
$target_path_file = 'images/' .basename($_FILES['upload']['name']);
move_uploaded_file($temp, $target_path_file);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.