我目前正在尝试使用 PHP 写入 txt 文件,我发现了这个小脚本:
<?php
$filename = 'testFile.txt';
$somecontent = "Add this to the file\n";
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote ($somecontent) to file ($filename)";
fclose($handle);
}
else {
echo "The file $filename is not writable";
}
?>
我收到一条成功消息,但文件中没有写入任何内容。即使我删除了 txt 文件,我仍然会收到成功消息
有谁知道如何解决这种情况?