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 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动