<?php
//写文件
//方案1 fopen(),fwrite(),fclose()
function writeFile($path,$string){
if (empty($path)) {
return false;
}
$dir = dirname($path);//返回路径中的目录部分。
if(!is_dir($dir)) {
mkdir($dir, 0777, true);
}
$file=fopen($path,'a'); //打开文件
if (!@fwrite($file,$string)) {
return false;
}
fclose($file);
return true;
}
$res = writeFile('test.txt','方案1 string'.time().'<br/>');
//方案2 与依次调用 fopen(),fwrite() 以及 fclose() 功能一样。
$res2 =file_put_contents('test.html','方案2 string'.time().'<br/>',FILE_APPEND);
if ($res2) {
echo 'Write success!';
} else {
echo 'Write failed!';
}
?>
写文件
最新推荐文章于 2022-11-26 14:21:09 发布