本文介绍了PHP创建txt文件并将其保存到根目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建文件并将其保存到站点的根目录,但是我不知道它在文件的创建位置,因为看不到任何文件.而且,如果可能的话,我需要每次都覆盖该文件.
I am trying to create and save a file to the root directory of my site, but I don't know where its creating the file as I cannot see any. And, I need the file to be overwritten every time, if possible.
这是我的代码:
$content = "some text here";
$fp = fopen("myText.txt","wb");
fwrite($fp,$content);
fclose($fp);
如何设置它保存在根目录上?
How can I set it to save on the root?
推荐答案
它将在与脚本相同的目录中创建文件.试试这个吧.
It's creating the file in the same directory as your script. Try this instead.
$content = "some text here";
$fp = fopen($_SERVER['DOCUMENT_ROOT'] . "/myText.txt","wb");
fwrite($fp,$content);
fclose($fp);
这篇关于PHP创建txt文件并将其保存到根目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!