【问题标题】:fopen alternativefopen 替代方案
【发布时间】:2012-10-14 11:28:16
【问题描述】:

我有一个简单的 php 脚本,它创建一个文件,添加一些内容并再次关闭它。但是我的主机禁用了 fopen 功能。我想知道我该如何解决这个问题。我的主人不会帮助我。这是我的代码:

$f = fopen($id."/adres.xml", "w");
fwrite($f, 'some content');
fclose($f);

我想知道有什么替代方案。我已经阅读了很多关于使用 cUrl 的内容,但在我看来,这更像是从其他网站获取文档并使用它,而不是创建文档(请告诉我是否可以这样做)。

所以,我的问题是,fopen 的替代品是什么(函数等)。

【问题讨论】:

标签: php fopen


【解决方案1】:
//to write    
file_put_contents('path_and_filename','content');
//to read:
file_get_contents('path_and_filename');

如果要追加到文件中:

file_put_contents('path_and_filename' , 'content' , FILE_APPEND );

您也可以锁定文件:

file_put_contents('path_and_filename' , 'content' , LOCK_EX );

看看下面的链接:

http://php.net/manual/en/function.file-put-contents.php

http://php.net/manual/en/function.file-get-contents.php

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-04
    • 1970-01-01
    • 2012-10-05
    • 2010-09-10
    • 2012-12-05
    • 2013-11-22
    • 2020-11-23
    相关资源
    最近更新 更多