4

我正在使用 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!";
}

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

警告: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' 到 '/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 上传文件出错,请重试!

文件或文件夹权限:

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

检查什么用户 php 正在运行

php> echo exec('whoami');
knel

谁能给我建议解决方案?

4

2 回答 2

3

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

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

于 2013-04-07T09:44:18.807 回答
0

我遇到过同样的问题。

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

于 2015-06-17T13:37:17.723 回答