move_uploaded_file权限被拒绝

时间:2013-12-18 07:54:17

标签: php

将图片上传到名为images的目录文件夹时出错。虽然我创建了一个文件夹images

发生错误

1. Warning: move_uploaded_file(images/Rachel Leigh Cook.jpg): failed to open stream: 
2. Permission denied in /usr/home/mer/public_html/salico/ZNote/php/image_upload_do.php 
3. Unable to move '/var/tmp/phpGV5fVF' to 'imagesRachel Leigh Cook.jpg' in 
   /usr/home/mer/public_html/salico/ZNote/php/image_upload_do.php 

我的代码

$upfile = ( isset( $_FILES['userfile'] ) ) ? $_FILES['userfile'] : '' ;

if ( is_array( $upfile ) ) {

    $file_name = $upfile['name'];
    $file_temp = $upfile['tmp_name'];

    $dir_file = 'images/'.$file_name;

    if ( is_uploaded_file( $file_temp ) ) {

        if ( move_uploaded_file( $file_temp, $dir_file ) ) {
            echo 'Successfully Uploaded';
        } else {
            echo 'Failed to upload';
        }
    }
}

我认为我的代码没有错。我是否需要编辑php.ini文件?

3 个答案:

答案 0 :(得分:1)

运行chmod命令到路径文件夹。

答案 1 :(得分:1)

尝试像这样运行chmod for images文件夹:

chmod -R 777 images 

还有php文件夹chmod -R 777 php

答案 2 :(得分:0)

转到相应的文件夹..在这种情况下images并运行。

chmod -R 777