php - fopen 无法在没有错误的服务器上运行
问题描述
我的代码在 Windows 环境中的本地 PHP 实例(版本 5.4.31)上运行良好。
但是当我在我的服务器上运行同一个文件时,它在 Centos 环境中的服务器(PHP 版本 5.4.16)上不起作用。
我的PHP代码:
<?php
//$myfile = fopen("testfile.txt", "w");
if (!file_exists("file.txt")) {
die('File does not exist');
}
clearstatcache();
// $fh = fopen("file.txt", "r") or die("can't open file");
$fh = fopen("file.txt", "r") or die($php_errormsg);
$sql = fread($fh, filesize("file.txt"));
error_reporting(E_ALL);
ini_set('display_errors',1);
?>
问题是文件没有生成,我无法看到错误日志,我在哪里可以看到错误,以便我可以找到相应的解决方案?
解决方案
通常是这样的:
<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
//$myfile = fopen("testfile.txt", "w");
if (!file_exists("file.txt")) { die('File does not exist'); }
clearstatcache();
// $fh = fopen("file.txt", "r") or die("can't open file");
$fh = fopen("file.txt", "r") or die($php_errormsg);
$sql = fread($fh,filesize("file.txt"));
?>
file.txt
应该在同一个文件夹中
┬root
|
|
└─┬www
|
├─ test4.php
|
├─ file.txt
|
推荐阅读
- java - 当图像尺寸很大时,RBGLuminanceSource.toString 会抛出 StackOverflowError
- reactjs - 如何设置反应选择选项的样式?
- python - Python:从列表中删除列表
- reactjs - 如何使用 create-react-library 加载 wasm 模块?
- javascript - Node.js 中一个奇怪的 for_of 循环问题:无法正确迭代
- python - Django 3.1 No reverse match at / not a registered namespace error
- java - 如何在 Matcher.replaceAll() 中进行条件正则表达式替换?
- python - 为什么 set 的大小可以比 python 中的 dict 大?
- oracle - 有没有办法为 Oracle PLSQL 中的表设置默认排序语句?
- qt - 如何在 QLineEdit 中键入 TAB?