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

move_uploaded_file failed to open stream: Permission denied - Mac

当我尝试使用以下代码在 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 

我仍然遇到错误,我正在使用 Yosemite,还有其他解决方案吗?

为您的目标(上传)文件夹设置相同的权限

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

此问题已通过更改权限解决,如 avobe 所述 并使目标文件夹位于应用程序 运行

所在的同一目录 {Root 而不是 Home }

图片上传路径

/Applications/XAMPP/xamppfiles/htdocs/emp/files/admin_assets/addsdassets/targrt_Folder

应用所在的文件夹路径 运行

/Applications/XAMPP/xamppfiles/htdocs/emp/files/admin_assets/addsdassets/inser_db.php

申请

sudo chmod 777 images/

到folder/directory,这是您用于存储图像的服务器文件夹。请检查哪个是您的文件夹。完全取决于你的选择。

您可以尝试更改保存图像的文件夹图像的所有者。可能有用。

chown ownername:group folder;

你必须给出文件夹的绝对地址

我是 运行 IIS 上的 Yii2 (Windows 10),我调整了路径并让它工作。请参阅下面的代码片段:

if($model->load(Yii::$app->request->post())) {

    $image = UploadedFile::getInstance($model, 'image');
    $model->image = $image->getBaseName().'.'.$image->extension;            
    if($model->save()) {
        $image->saveAs('uploads/'.$model->image);//Notice the path change here
        return $this->redirect(['view', 'id' => $model->ID]);
    }

}
else {

    return $this->render('update-image', [
        'model' => $model
    ]);
}

希望对您有所帮助。

我正在使用ubuntu,一旦遇到这个问题,我通过更改我要将文件移动到其中的文件夹的所有访问权限来解决这个问题'create and delete files'。请参阅下面的屏幕截图:

此问题是由权限受限引起的。要解决扩展或更改您对文件夹的权限,请使用:chmod -R 777 folder-path.

例如:

chmod -R 777 /opt/lampp/htdocs/php/aitech/images/passport_photos