Php代码用于创建文件

时间:2014-04-13 03:19:40

标签: php fopen

我们需要在livehost服务器上创建一个文件。在实时服务器中输入URL后,我们需要创建一个特定路径的文件。我正在使用godaddy服务器,请提示您是否有任何帮助?

2 个答案:

答案 0 :(得分:0)

尝试打开文件,如果它不存在,它会创建它

$handle = fopen("http://www.yoursite.com/file.txt", "a+");
如果需要,

a + in fopen允许您写入文件,如果要覆盖任何现有内容,请使用w +

fwrite($handle, $new_file_content);

完成后释放内存

fclose($handle);

答案 1 :(得分:0)

另一种选择:

$fileContents = "File contents";
if(false !== file_put_contents("/path/to/file.txt", $fileContents)){
    echo 'write successful';
}