【发布时间】:2013-07-10 10:48:23
【问题描述】:
如果文件不存在,我正在尝试将文件检查到某个位置。但是 file_exist 总是返回 false..
为检查文件是否存在添加的功能
$file_path = "myconfigfile.config";
private function LoadFile( $file_path ) {
$contents = '';
if(file_exists($file_path)) {
$handle = fopen( $file_path, "r" );
while( !feof( $handle ) ) {
$contents .= fread( $handle, 8192 );
}
@fclose( $handle );
}
return $contents;
}
两个文件都存在于同一个文件夹中,但仍然没有给出正确的输出
请帮帮我
【问题讨论】:
-
当前工作目录不是您认为的当前工作目录。 总是在 PHP 中使用当前目录的相对路径:
__DIR__ . '/relative/path/to/file'
标签: php file-exists configuration-files