douna4762 2014-12-14 06:04
浏览 80

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

I'm new to PHP and I seem to have a problem uploading file to the web server. I've made myself a simple form and have a PHP file to control the uploading but every time I run the code, I get an error. Here is the code:

<?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');
}
?>

and this is the 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

Thanks in advance!

  • 写回答

1条回答 默认 最新

  • douqi0090 2014-12-14 06:15
    关注

    error assign vs evaluate if ($error = 0) should be if ($error == 0)

    name is from basename. also declare the target before.

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

报告相同问题?

悬赏问题

  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了