php move_uploaded_file(): 无法将“/tmp/phpiS3dQA”移动到“/var/www/html/mysite/uploads/PNGWallpaper.png”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15860920/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 10:05:02  来源:igfitidea点击:

move_uploaded_file(): Unable to move '/tmp/phpiS3dQA' to '/var/www/html/mysite/uploads/PNGWallpaper.png

phpapachefile-uploaduploadfedora

提问by kn3l

I am using Fedora 16, PHP5.x and Apach2.x

我正在使用 Fedora 16、PHP5.x 和 Apache2.x

$target_path = "/var/www/html/mysite/uploads/";
$target_path = $target_path . basename( $_FILES['photo_video']['name']); 
if(move_uploaded_file($_FILES['photo_video']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['photo_video']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}

When I try to upload I always got the message :

当我尝试上传时,我总是收到消息:

Warning: move_uploaded_file(/var/www/html/mysite/uploads/PNGWallpaper.png): failed to open stream: Permission denied in /var/www/html/mysite/modules/content/cj_c.php on line 44 Call Stack: 0.0002 132524 1. {main}() /var/www/html/mysite/index.php:0 0.0016 153684 2. include_once('/var/www/html/mysite/modules/content/cj_c.php') /var/www/html/mysite/index.php:36 0.0022 160500 3. move_uploaded_file() /var/www/html/mysite/modules/content/cj_c.php:44 Warning: move_uploaded_file(): Unable to move '/tmp/phpiS3dQA' to '/var/www/html/mysite/uploads/PNGWallpaper.png' in /var/www/html/mysite/modules/content/cj_c.php on line 44 Call Stack: 0.0002 132524 1. {main}() /var/www/html/mysite/index.php:0 0.0016 153684 2. include_once('/var/www/html/mysite/modules/content/cj_c.php') /var/www/html/mysite/index.php:36 0.0022 160500 3. move_uploaded_file() /var/www/html/mysite/modules/content/cj_c.php:44 There was an error uploading the file, please try again!

警告:move_uploaded_file(/var/www/html/mysite/uploads/PNGWallpaper.png):无法打开流:/var/www/html/mysite/modules/content/cj_c.php 中第 44 行调用堆栈中的权限被拒绝: 0.0002 132524 1. {main}() /var/www/html/mysite/index.php:0 0.0016 153684 2. include_once('/var/www/html/mysite/modules/content/cj_c.php') /var /www/html/mysite/index.php:36 0.0022 160500 3. move_uploaded_file() /var/www/html/mysite/modules/content/cj_c.php:44 警告:move_uploaded_file():无法移动'/tmp/ phpiS3dQA' to '/var/www/html/mysite/uploads/PNGWallpaper.png' in /var/www/html/mysite/modules/content/cj_c.php on line 44 Call Stack: 0.0002 132524 1. {main}( ) /var/www/html/mysite/index.php:0 0.0016 153684 2. include_once('/var/www/html/mysite/modules/content/cj_c.php') /var/www/html/mysite/index .php:36 0.0022 160500 3.move_uploaded_file() /var/www/html/mysite/modules/content/cj_c.php:44 上传文件时出错,请重试!

File or folder permission:

文件或文件夹权限:

drwxrwxrwx. 465 root root 36864 Apr  6 23:20 tmp
drwxrwxrwx. 2 knel knel 4096 Apr  6 22:47 uploads

php.ini

配置文件

file_uploads = On
max_file_uploads = 20

check what user php is running as

检查用户 php 正在以什么身份运行

php> echo exec('whoami');
knel

Who can suggestion me the solution ?

谁能建议我解决方案?

采纳答案by ivans

Permission denied means that the user under which PHP is running doesn't have a write permission to one of the directories in your destination path (/var/www/html/mysite/uploads/)

权限被拒绝意味着运行 PHP 的用户对目标路径 (/var/www/html/mysite/uploads/) 中的目录之一没有写权限

You can use thistool to check permissions on the full path down to the target directory.

您可以使用工具检查对目标目录的完整路径的权限。

回答by Rex

I had the same issue.

我遇到过同样的问题。

My solution: make sure the destination folder have the "x" permission( 700 ), not only the write permission.

我的解决方案:确保目标文件夹具有“x”权限( 700 ),而不仅仅是写入权限。