PHP的move_uploaded_file错误:Mac上的权限被拒绝

时间:2014-12-14 06:04:49

标签: php

我是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

提前致谢!

1 个答案:

答案 0 :(得分:0)

错误分配vs评估 if ($error = 0)应为if ($error == 0)

name来自basename。也在之前宣布目标。

$target_path_file = 'images/' .basename($_FILES['upload']['name']);
move_uploaded_file($temp, $target_path_file);