php打开文件失败
2015-10-13 10:13
501 查看
1、在linux环境下用PHP脚本fopen打开文件“t1.txt”,路径写成“/test/t1.txt”时出错
Warning: fopen(/test/t1.txt) [function.fopen]: failed to open stream: No such file or directory
in /var/www/test/5-3.php on line 24
Unable to open file!
原始代码如下:
$file = fopen("/test/t1.txt", "r") or exit("Unable to open file!");
//Output a line of the file until the end is reached
while(!feof($file))
{
echo fgets($file). "<br />";
}
fclose($file);
2、解决方法
我查了一些资料发现是路径不完整造成的,写成 /var/www/test/t1.txt 就可以了。
修改后的代码:
$file = fopen("/var/www/test/t1.txt", "r") or exit("Unable to open file!");
//Output a line of the file until the end is reached
while(!feof($file))
{
echo fgets($file). "<br />";
}
fclose($file);
Warning: fopen(/test/t1.txt) [function.fopen]: failed to open stream: No such file or directory
in /var/www/test/5-3.php on line 24
Unable to open file!
原始代码如下:
$file = fopen("/test/t1.txt", "r") or exit("Unable to open file!");
//Output a line of the file until the end is reached
while(!feof($file))
{
echo fgets($file). "<br />";
}
fclose($file);
2、解决方法
我查了一些资料发现是路径不完整造成的,写成 /var/www/test/t1.txt 就可以了。
修改后的代码:
$file = fopen("/var/www/test/t1.txt", "r") or exit("Unable to open file!");
//Output a line of the file until the end is reached
while(!feof($file))
{
echo fgets($file). "<br />";
}
fclose($file);
相关文章推荐
- ThinkPHP技巧
- php如何向文件中写入换行
- PHP安装所最到的问题-解决方案
- TP的SDK的调用
- editplus 怎么替换为换行
- php打包文件夹成zip文件
- PHP基础
- 分享六:php脚本守护进程
- u-boot TFTP: 'Access violation' (2)
- php 多进程解决代码常驻内存的问题php 多进程解决代码常驻内存的问题
- 手动编译PHP
- PHP从头开始-3
- PHP:Fatal error: Class 'COM' not found in … 的处理办法
- PHP 编程中 10 个最常见的错误,你犯过几个?
- Win.ini的操作函数GetProfileInt和WriteProfileString
- PHP如何通过传引用的思想实现无限分类(代码简单)
- PHP实现连接设备、通讯和发送命令的方法
- 10个php函数实用却不常见
- 现在写 PHP,你应该知道这些
- PHP部分字符串函数汇总