php move_uploaded_file 无法打开流:权限被拒绝 - Mac
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31915957/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
move_uploaded_file failed to open stream: Permission denied - Mac
提问by AaoIi
While i am trying to move_uploaded_file in php with following code :
当我尝试使用以下代码在 php 中 move_uploaded_file 时:
if(is_uploaded_file($_FILES['fileupload2']['tmp_name'])){
move_uploaded_file($_FILES['fileupload2']['tmp_name'], "images/".$_FILES['fileupload2']['name']);
}
I've got this error saying:
我有这个错误说:
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
i tried in the terminal and didn't work:
我在终端中尝试过,但没有用:
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
I am still getting the error and i am using Yosemite, any other solution ?
我仍然收到错误,我正在使用 Yosemite,还有其他解决方案吗?
回答by AaoIi
回答by ManiMuthuPandi
Set the same permission for your target(uploading) folder
为您的目标(上传)文件夹设置相同的权限
回答by UserszrKs
This problem solved by changing permission as described avobe and making the target folder in the same directory {Root rather than Home } in which application is running
这个问题是通过更改权限来解决的
path for image upload
图片上传路径
/Applications/XAMPP/xamppfiles/htdocs/emp/files/admin_assets/addsdassets/targrt_Folder
path of folder in which application is running
运行应用程序的文件夹路径
/Applications/XAMPP/xamppfiles/htdocs/emp/files/admin_assets/addsdassets/inser_db.php
回答by Ravi Kumar Yadav
You can try after changing owner for the folder images where you are saving the images. It may work.
您可以在更改保存图像的文件夹图像的所有者后尝试。它可能会起作用。
chown ownername:group folder;
you have to give absolute address of the folder
你必须给出文件夹的绝对地址
回答by user2288580
I was running Yii2 on IIS (Windows 10) and I tweaked the path and got it working. See code snippet below:
我在 IIS(Windows 10)上运行 Yii2,我调整了路径并让它工作。请参阅下面的代码片段:
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
]);
}
Hope this helps.
希望这可以帮助。
回答by Rajat Yadav
回答by Pramod Singh
apply
申请
sudo chmod 777 images/
to the folder/directory which is your server folder to store images. Please check which is your folder. Totally depends on your choice.
到文件夹/目录,这是您用于存储图像的服务器文件夹。请检查哪个是您的文件夹。完全取决于你的选择。