的file_put_contents没有创造txt文件 [英] file_put_contents not creating txt file

查看:609
本文介绍了的file_put_contents没有创造txt文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我有当浏览器浏览器浏览到该网页正在运行的PHP脚本。我正在试图做的是运行脚本存储变量时写的文本文件。该文件夹的所有者是Apache的,但每个人都有读写,严格出于测试目的。 (我想这可能是一个权限问题)SELINUX是在服务器上启用,当我从控制台运行该脚本,它会创建文本文件蛮好的,在正确的目录。

I currently have a php script that is running when a browser browser browses to the webpage. What I'm trying to do is write a text file when the script runs that stores a variable. The owner of the folder is apache, but everyone has read write, strictly for testing purposes. (I thought it might be a permissions issue) SELINUX is enabled on the server, and when I run the script from console it creates the text file just fine, and in the right directory.

file_put_contents("My working file location", $myString);

我用这条线要尽量写,创建文本文件,我知道我的文件位置的作品我因为...可以运行它,并在离线模式下,也就是创建通过控制台运行它。问题是,我试图写变量是通过HTTP POST填充,当我通过浏览器运行该脚本,或者当Apache运行脚本,它不写或创建文件。什么我需要做的,允许访问写/更改语法明智的,得到这个剧本写这个文本文件?

I'm using this line to try to write and create the text file, I know that my file location works becaus I can run it and create it in offline mode, I.E. running it through console. The problem is that the variable I'm trying to write is populated through HTTP Post, and when I run the script through the browser, or when apache runs the script, it does not write or create the file. What do I need to do to allow access to write/change syntax wise to get this script to write this text file?

推荐答案

您的问题很可能会写信给你指定的文件位置。进入该目录,并检查与 LS的权限和组所有权命令:

Your problem is likely due to apache not having permissions to write to the file location you specified. Go to that directory and check the permissions and group ownership with the ls command:

cd "My working file location"
ls -l .

有在显示的权限,所有者和组的目录输出三列。最有可能的,他们的所有者是root,并没有对阿帕奇来写入该目录。权限

There are three columns in the output that show the permissions, owner, and group for the directory. Most likely they are owned by root and don't have permissions for apache to write to the directory.

如果是这样的话,那么你会看到一个错误出现在你的Apache日志当它试图创建该文件。尝试拖尾你的日志在浏览器中运行该脚本时:

If this is the case, then you will see an error appear in your apache log when it tries to create the file. Try tailing your logs while running the script in your browser:

tail -f /var/log/apache2/error.log

这篇关于的file_put_contents没有创造txt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆