<?php
$filename = "Changelog.txt";
$newdata = $_POST['newd'];
if ($newdata != '')
{
$fw = fopen($filename, 'w') or die('Could not open file! Error 1');
$fb = fwrite($fw,stripslashes($newdata)) or die('Could not write to file');
fclose($fw);
}
$fh = fopen($filename, "r") or die("Could not open file!");
$data = fread($fh, filesize($filename)) or die("Could not read file! Error 2");
fclose($fh);
echo
"<form action='$_SERVER[php_self]' method= 'post' >
<textarea name='newd' cols='100%' rows='50'> $data </textarea>
<input type='submit' value='Change'>
</form>";
?>
所以我从谷歌中找到了一个代码来添加文件编辑器,它成功地将文件显示给编辑器,但是当我添加新行并单击更改时,它说"Could not open file"
.你能帮帮我吗?
此编辑器可以打开文件进行读取,当您尝试打开文件进行写入时会失败。
这可能不是 php 问题。是文件系统阻止了写入访问。有几种解决方案:授予目录 777 权限,让您的网络用户拥有该目录或让它加入具有权限的组,...
导航到日志目录并尝试 sudo chmod -R 777 。
我想你有Linux。
文件路径肯定是错误的,请检查路径并给出绝对路径。
例:
$filename = "D:'project'Changelog.txt";