dtiopy6088 2012-01-08 12:27
浏览 28
已采纳

为什么我不能在PHP中使用chmod()上传文件?

I want to upload an image on a remote host (Everything is ok locally).

I've used the code below like my other previous projects to do it:

if (move_uploaded_file($_FILES["scan"]["tmp_name"], 'images/scans/1.jpg')) {
   chmod ('images/scans/1.jpg','0644');
}

But every time I run this code in the internet, I get an error:

Warning: move_uploaded_file(images/profile/Mordent.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in ...

I have to change scans directory permission to 0777 and then I can upload images. Otherwise I can not. It's very strange for me. I've used this code in many times in different projects and I had not any problem with it.

  • 写回答

2条回答 默认 最新

  • dongpeiwei8589 2012-01-08 12:32
    关注

    images/scans/ must be writable by the web server user, and should not need to be 0777, which is world-writable. First, images must be readable by the web server user, having a 5 in the last position (like 0755). The scans directory must be owned by the web server user or writable by it. It is preferable to have it owned by the web server user, where its permissions can also be 0755.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 QT6颜色选择对话框显示不完整
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下