用于编写我使用以下代码,这是非常好和简单的工作,现在我有这个问题我们已经知道在窗口中 260 个字符允许文件名问题从这里开始 在代码中,如果文件不写入,可以选择停止和终止进程(或死亡("无法打开文件");)现在我想要简单,如果某些原因文件不写入显示回声不写入并继续处理。我试过了,但它给了我错误
我的写入函数
function write($post, $myFile){
$fh = fopen($myFile, 'a+') or die("can't open file");
fwrite($fh, $post);
fclose($fh);
}
如果对某物的长度有限制,那么你总是可以事先检查东西的长度,如果你不希望你的代码退出,那么不要使用 die()
.
function write($post,$myFile){
if( strlen($myfile) > 260 ) {
echo "Filename too long";
return false;
} else {
if( ! $fh = fopen($myFile, 'a+') ) {
echo "can't open file";
return false;
}
fwrite($fh, $post);
fclose($fh);
return true;
}
}
试试这个,
function write($post,$myFile)
{
$fh = @fopen($myFile, 'a+');
if($fh)
{
fwrite($fh, $post);
fclose($fh);
}
else
{
echo "can't open file";
}
}