doureng1083 2013-09-27 21: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 23: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条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大