PHP读写文件的错误!
公亮 2005-03-29 04:35:59 temp.html和写文件的这个程序是在一个根目录下的,我运行下面的写文件操作程序,却提示出错!
Warning: fopen(temp.html) [function.fopen]: failed to open stream: No such file or directory in F:\test\8.php on line 5
Warning: filesize() [function.filesize]: stat failed for temp.html in F:\test\8.php on line 6
Warning: fread(): supplied argument is not a valid stream resource in F:\test\8.php on line 6
Warning: fopen(test/test.html) [function.fopen]: failed to open stream: No such file or directory in F:\test\8.php on line 13
文件:test/test.html不可写,请检查其属性后重试!
这个是怎么回事情?明显的一个读失败,一个写失败!
请各位高手帮忙
下面是写文件操作的代码!
<?
$title = "拓迈国际测试模板";
$file = "TwoMax Inter test templet,author:_Max>Matrix@Two_Max";
$fp=fopen("temp.html","r");
$content = fread($fp,filesize ("temp.html"));
$content = str_replace ("{file}",$file,$content);
$content = str_replace ("{title}",$title,$content);
$filename = "test/test.html";
$handle = fopen ($filename,"w"); //打开文件指针,创建文件
/*
检查文件是否被创建且可写
*/
if (!is_writable ($filename)){
die ("文件:".$filename."不可写,请检查其属性后重试!");
}
if (!fwrite ($handle,$content)){ //将信息写入文件
die ("生成文件".$filename."失败!");
}
fclose ($handle); //关闭指针
die ("创建文件".$filename."成功!");
?>