我试图读取使用的file_get_contents()的文件,但我得到一个“未能打开流”的警告,当我尝试做没有绝对路径。奇怪的file_get_contents行为
<?php
$file = 'C:\wamp\vhosts\testsite.com\a\new.txt'; //works
$file = '\a\new.txt'; //didn't work
$file = '/a/new.txt'; //didn't work
echo file_get_contents($file);
使用WAMP ,所以不存在权限问题。 我的问题是,什么是错的,使用相对路径?提前
谢谢!
'$ file ='a/new.txt';'或'$ file ='../a/new。 txt';'取决于脚本的执行位置。你也可以做'/ var/user/you/public_html/folder/new.txt',这就是为什么你的第二和第三不起作用。 – 2014-11-05 17:16:56
相对的意思,相对于你所在的文件夹。使用'echo getcwd()。 “\ n”;'查看当前目录。如果不是'C:\ wamp \ vhosts \ testsite.com',那么你可以使用'chdir()'去那里或者把路径追加到' include_path'。 – 2014-11-05 17:20:10