第一种:
<?php
$filename = 'test.txt';
$somecontent = "this is test string.";
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
echo "不能打开文件 $filename";
exit;
}
// 将$somecontent写入到我们打开的文件中。
if (fwrite($handle, $somecontent) === FALSE) {
echo "不能写入到文件 "e;{$filename}"e;";
exit;
}
echo "已把"e;{$somecontent}"e;写入到文件"e;{$filename}"e;";
fclose($handle); //将指针关闭
} else {
echo "文件{$filename}不可写.";
}
?>
第二种:
<?php
$filename = "test.txt";
$content = "this is test string.";
$put = file_put_contens($filename,$content);
if(!put)
exit("write failed");
echo "write success";
?>
评论