douju2012 2018-10-30 04:07
浏览 244
已采纳

在浏览器中访问时,file_put_contents不起作用

I use php5.6 and Apache2.4.6 in centOS7.5
I put a php file in /var/www/html

like this :

<?php    
echo (__DIR__ . "/test.text");    
file_put_contents(__DIR__ . "/test.text","test text");  

when I access this file through web browser(google chrome), file_put_contents do not function. but,when I execute this file in console, file_put_contents do function. it make test.text file.

Is this problem due to server setting? or some php function doesn't work in access by a browser?

this is httpd/error_log

[Tue Oct 30 13:35:13.191011 2018] [:error] [pid 15037] [client XX.XXX.XX.XXX:29220] PHP Warning:  
file_put_contents(/var/www/html/test.text): failed to open stream: Permission denied in /var/www/html/fpc2.php on line 3

but, this file's permission is 777.

  • 写回答

1条回答 默认 最新

  • doufengsui7449 2018-10-30 04:12
    关注

    Right. So it is a permissions problem. You need to make sure that the "user" that runs the php code has permission to write into the directory. I don't know to which user to give the permission, but it may be "web". Try:

    sudo chgrp -R web /var/www/html

    then

    sudo chmod -R g+w *

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题