PHP中的绝对路径报错
我是PHP中打开一个txt文件,用的是绝对路径,但是报错了。
<?php
$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);