file_put_contents

时间:2024-09-16 13:42:24编辑:莆田seo君

PHP file_put_contents函数写入不了txt文件 代码如图

1、查看一下你写入的文件路径是否正确2、那个文件是否有写入的权限3、file_put_contents方法是否存在依据你给的代码图片,将其修改了一下,你试试看看行不行: $v) {$html = '这是写入的内容'."\r\n";$html .= '写入的内容要是字符串!'."\r\n";$html .= '.....';}$c = $html;}// 写入if(file_exists('file_put_contents')){file_put_contents($a, $c);}else{$handle = fopen($a, 'w+');fwrite($handle, $c);fclose($handle);}}?>若有任何疑问,欢迎追问......

file_put_contents问题,写文件的时候同时改变被写文件的编码?

$this_php_file_charset = 'gb2312';
$f="post.txt";
$p="I love you. 撒旦法";
$p=iconv($this_php_file_charset,"utf-8",$p);
file_put_contents($f,$p);

$this_php_file_charset:你的当前php文件的编码(编码系内包含的编码,gb2312属于ansi编码系,所以在ansi编码文件内的中文,可以看作是gb2312)
file_put_contents属于独占锁定重写,如果需要追加的话,用fopen


php如何把创建的文件自动存到指定的目录?

对文件的操作,最好使用绝对路径,否则你会搞乱的
好的习惯是,定义一个
define(ROOT,dirname(__FILE__));//当前文件的物理地址(结果可能是D:\\html\\)
然后写保存文件的时候,你的fname应该是ROOT . '/' . $filename;


你的情况,可能是ROOT . '/myhtml/' . date('Y-m-d') . rand(0,999) . '.html';

如果输出它,它可能是d:\wwwroot\myhtml\2009-10-13\333.html


$of = fopen($fname,'w');

或者在php5下直接 file_put_contents($fname,$content);


上一篇:暗黑3练级

下一篇:中信建投通达信