在Linux服务器上使用php 5.2.17。我的办公生产机器是安装了Service Pack 1的Windows7 Professional。
拼命想让fopen()
在我的本地机器上找到并打开一个.csv文件,以便将记录导入服务器上现有的MySQL数据库,但到目前为止,这一切都是徒劳的。持续获取"无法打开流"错误消息。
这是代码的一部分,带有解释性注释/服务器响应,包括我尝试过的注释:
ini_set('track_errors', 1); // Set just to make sure I was seeing all of the rrror codes
ini_set ('user_agent', $_SERVER['HTTP_USER_AGENT']); // Tried after reading a note; no effect
error_reporting(E_ALL); // Again, just to make sure all error codes visible!
echo(get_include_path()."<br />"); // Initially returns: .:/usr/local/php5/lib/php
set_include_path("C:'SWSRE''"); // Have tried with BOTH forward and backslashes, BOTH single and doubled, in every conceivable combination!
ini_set('safe_mode_include_dir',"C:'SWSRE"); // Ditto here for slashes!
echo(get_include_path()."<br />"); //NOW echoes "C:'SWSRE'"
clearstatcache(); // Just in case this was a problem -- added after reading note @ php.net
$file = "Individuals.txt"; // This absolutely DOES exist locally in C:'SWSRE' (29Mb)
// Inserted following tests to see if it even SEES the file. It does NOT.
if (file_exists("Individuals.txt")) {
echo("File EXISTS!!!<br />");
} else {
echo("File does NOT exist!<br />"); // Echoes "File does NOT exist!"
}
if(is_readable($file)) {
echo 'readable' ;
} else {
echo 'NOT readable!<br />'; // Echoes "NOT readable!"
}
if(is_writable($file)) {
echo 'writable ' ;
} else {
echo 'NOT writable!<br />'; // Echoes "NOT readable!"
}
$handle = fopen("Individuals.txt", "r+", TRUE);
以下是最后的PHP错误消息:
警告:fopen(Individuals.txt)[function.fopen]:无法打开流:在/home/content/b/u/r/burtsweeto/html/ADREImport.php的第145行中没有这样的文件或目录array(4){["type"]=>int(2)["message"]=>string(118)"fopen(Individuals.txt)[function.fopen]:无法打开流:没有这样的文件或目录"["file"]=>字符串(56)"/home/content/b/u/r/burtsweeto/html/ADREImport.php"["line"]=>int(145)}
最后,我尝试将该文件放在运行PHP脚本的目录中;它确实在那里工作得很正确!我只是想通过在导入之前不必上传一个巨大的文件来尽量减少最终用户持续的头痛。
有什么我没有尝试过的建议吗?
添加$file
的完整路径,如下所示:
$file = "C:''SWSRE''Individuals.txt";
CCD_ 3和CCD_;他们调整包括路径,这与所有的路径不同。file_exists()
需要一个绝对路径或相对于调用它的PHP文件的路径。它不受set_include_path()
或ini_set('safe_mode_include_dir',...)
的影响