Home > Backend Development > PHP Tutorial > PHP中的绝对路径报错解决方法

PHP中的绝对路径报错解决方法

WBOY
Release: 2016-06-13 10:27:11
Original
1768 people have browsed it

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);

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template