dongnao9525
2013-12-18 07:54
浏览 66
已采纳

move_uploaded_file权限被拒绝

I'm getting error in uploading image to directory folder named images. Though I created a folder images.

Error Occur

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 

My code

$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';
        }
    }
}

I think there is nothing wrong in my code. Do I need to edit the php.ini file?

图片转代码服务由CSDN问答提供 功能建议

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

发生错误

  1。 警告:move_uploaded_file(images / Rachel Leigh Cook.jpg):无法打开流:
2。  /usr/home/mer/public_html/salico/ZNote/php/image_upload_do.php 
3中的权限被拒绝。 无法将'/ var / tmp / phpGV5fVF'移动到'n /usr/home/mer/public_html/salico/ZNote/php/image_upload_do.php 
  中的'imagesRachel Leigh Cook.jpg'  
 
 

我的代码

  $ 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 if(is_uploaded_file($ file_temp)){
 
 if if(move_uploaded_file($ file_temp,$ dir_file)){
 echo'Fenitively 上传了'; 
}其他{
 echo'Failed to upload'; 
} 
} 
} 
   
 
 

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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • douyin4875 2013-12-18 09:29
    已采纳

    Try to run chmod for images folder like this :

    chmod -R 777 images 
    

    And also on php folder chmod -R 777 php

    点赞 打赏 评论
  • dongyizhuang0134 2013-12-18 08:03

    run chmod command to path folder.

    点赞 打赏 评论
  • doulian8554 2013-12-18 08:29

    Go to respective folder .. in this case images and run.

    chmod -R 777
    
    点赞 打赏 评论

相关推荐 更多相似问题