doureng1083 2013-09-27 13:51
浏览 89
已采纳

PHP - 写入服务器文件夹被拒绝

I have done chmod -R 777 on the root folder, but I'm still unable to successfully
upload (thus, write) to the uploaded folder!

Do I also have to change the php.ini file?

//$target_path = "http://localhost/photoServerProject/uploaded";
$target_path = "/photoServerProject/uploaded";
$fname = $_FILES["file"]["name"];
$upload_location = $target_path.'/'.$fname;

move_uploaded_file($_FILES["file"]["tmp_name"], $upload_location);

echo 'Moving file: ' . $fname . '</br></br>to: ' . $upload_location;
//echo "<img src=$upload_location>";

if(is_writeable($upload_location)){
    echo '</br></br>Location <strong>is</strong> writeable ';
} else {
    echo '</br></br>Location <strong>is NOT</strong> writeable ';
}

Output:

Moving file: camera.jpeg

to: /photoServerProject/uploaded/camera.jpeg

Location is NOT writeable

  • 写回答

3条回答 默认 最新

  • douzhuan4406 2013-09-27 15:16
    关注

    I was misunderstanding the difference between server and local disk directory structures. Namely, the root folders are different.

    I'm surprised nobody brought up this issue.

    Here's the solution:

    <?php
    
        $local_target = "~/webdev/photoServerProject/uploaded/";
        $server_target = $_server['DOCUMENT_ROOT'] . "/photoServerProject/uploaded/";
    
        $fname = $_FILES["file"]["name"];
    
        $local_file_location = $local_target.$fname;
        $server_file_location = $server_target.$fname;
    
        move_uploaded_file($_FILES["file"]["tmp_name"], $local_file_location);
    
        echo 'Moving file: ' . $fname . '</br></br>to local path: ' . $local_file_location;
        echo '</br></br> But on the server it resides in : ' . $server_file_location;
        echo '</br></br> See?';
        echo "</br></br> <img src=$server_file_location>";
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部