move_uploaded_file无法打开流:权限被拒绝 - Mac

2022-08-30 23:06:03

当我试图用下面的代码在php中move_uploaded_file时:

if(is_uploaded_file($_FILES['fileupload2']['tmp_name'])){

        move_uploaded_file($_FILES['fileupload2']['tmp_name'], "images/".$_FILES['fileupload2']['name']);

    }

我有这个错误说:

Warning: move_uploaded_file(images/VIDEO_TS.VOB): failed to open stream: Permission denied in /Applications/XAMPP/xamppfiles/htdocs/Week3/Lesson2/do_upload.php on line 24

我在终端中尝试,但不起作用:

sudo CHMOD 775 /Applications/XAMPP/xamppfiles/htdocs/Week3/Lesson2/do_upload.php 

sudo chmod -R 0755 /Applications/XAMPP/xamppfiles/htdocs/Week3/Lesson2/do_upload.php 

sudo chown nobody /Applications/XAMPP/xamppfiles/htdocs/Week3/Lesson2/do_upload.php 

我仍然收到错误,我正在使用优胜美地,任何其他解决方案?


答案 1

我的解决方案是授予图像文件夹和php文件的权限,方法是转到文件>右键单击>>获取信息,然后将所有权限更改为如下图所示。read&write

enter image description here


答案 2

我正在使用ubuntu,一旦遇到此问题,我就通过更改要在其中移动文件的文件夹的所有访问权限来解决此问题,以“创建和删除文件”。看下面的截图:

enter image description here


推荐