PHP中的绝对路径报错解决方法
程序员文章站
2024-01-22 13:37:28
...
PHP中的绝对路径报错
我是PHP中打开一个txt文件,用的是绝对路径,但是报错了。
$file = fopen("../PHp.txt", "r");
$filesize = filesize("PHp.txt");
echo fread($file,$filesize);
fclose($file);
?>
Warning: fopen(../PHp.txt) [function.fopen]: failed to open stream: No such file or directory in F:\APMServ5.2.6\APMServ5.2.6\www\htdocs\newfile.php on line 7
Warning: filesize() [function.filesize]: stat failed for PHp.txt in F:\APMServ5.2.6\APMServ5.2.6\www\htdocs\newfile.php on line 8
Warning: fread(): supplied argument is not a valid stream resource in F:\APMServ5.2.6\APMServ5.2.6\www\htdocs\newfile.php on line 9
Warning: fclose(): supplied argument is not a valid stream resource in F:\APMServ5.2.6\APMServ5.2.6\www\htdocs\newfile.php on line 10
------解决方案--------------------
把它放入你的项目文件夹中去。目前是在根目录以外了。
------解决方案--------------------
你的程序在 F:\APMServ5.2.6\APMServ5.2.6\www\htdocs\newfile.php
你的文件在 C:\Users\Administrator\Desktop\PHP.txt
所以访问 PHP.txt 需要
$fn = 'C:/Users/Administrator/Desktop/PHP.txt';
$file = fopen($fn, "r");
$filesize = filesize($fn);
echo fread($file,$filesize);
fclose($file);
我是PHP中打开一个txt文件,用的是绝对路径,但是报错了。
$file = fopen("../PHp.txt", "r");
$filesize = filesize("PHp.txt");
echo fread($file,$filesize);
fclose($file);
?>
Warning: fopen(../PHp.txt) [function.fopen]: failed to open stream: No such file or directory in F:\APMServ5.2.6\APMServ5.2.6\www\htdocs\newfile.php on line 7
Warning: filesize() [function.filesize]: stat failed for PHp.txt in F:\APMServ5.2.6\APMServ5.2.6\www\htdocs\newfile.php on line 8
Warning: fread(): supplied argument is not a valid stream resource in F:\APMServ5.2.6\APMServ5.2.6\www\htdocs\newfile.php on line 9
Warning: fclose(): supplied argument is not a valid stream resource in F:\APMServ5.2.6\APMServ5.2.6\www\htdocs\newfile.php on line 10
------解决方案--------------------
把它放入你的项目文件夹中去。目前是在根目录以外了。
------解决方案--------------------
你的程序在 F:\APMServ5.2.6\APMServ5.2.6\www\htdocs\newfile.php
你的文件在 C:\Users\Administrator\Desktop\PHP.txt
所以访问 PHP.txt 需要
$fn = 'C:/Users/Administrator/Desktop/PHP.txt';
$file = fopen($fn, "r");
$filesize = filesize($fn);
echo fread($file,$filesize);
fclose($file);
相关文章
相关视频
下一篇: php each()函数的小例子
推荐阅读