存在的本地文件上的PHP fopen()

存在的本地文件上的PHP fopen(),php,linux,windows,fopen,Php,Linux,Windows,Fopen,在Linux服务器上使用PHP5.2.17。我的office生产机器是Windows7 Professional,安装了Service Pack 1 拼命尝试(到目前为止是徒劳的)让fopen()在我的本地机器上查找并打开一个.csv文件,以便将记录导入服务器上现有的MySQL数据库。始终获取“无法打开流”错误消息 下面是代码的一部分,带有解释性说明/服务器响应,包括关于我尝试过的内容的说明: ini_set('track_errors', 1); // Set just to make s

在Linux服务器上使用PHP5.2.17。我的office生产机器是Windows7 Professional,安装了Service Pack 1

拼命尝试(到目前为止是徒劳的)让
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);
ini\u集('track\u errors',1);//设置只是为了确保我看到了所有的rrror代码
ini_集('user_agent',$_SERVER['HTTP_user_agent');//读了一张纸条后试过;无效
错误报告(E_ALL);//同样,只是为了确保所有错误代码都可见!
echo(get_include_path().“
”);//最初返回:.:/usr/local/php5/lib/php 设置包含路径(“C:\SWSRE\\”;//在每一个可以想象的组合中,你都尝试过向前和向后的斜杠,单斜杠和双斜杠! ini_集('safe_mode_include_dir',“C:\SWSRE”);//斜杠也一样! echo(get_include_path().“
”)//现在回显“C:\SWSRE\” clearstatcache();//以防万一,这是一个问题——在阅读note@php.net后添加 $file=“personals.txt”;//这绝对存在于C:\SWSRE\(29Mb)中的本地 //插入以下测试,以查看它是否看到该文件。事实并非如此。 如果(文件_存在(“personals.txt”)){ echo(“文件存在!!!
”); }否则{ echo(“文件不存在!
”);//echos“文件不存在!” } 如果(是否可读($file)){ 回声“可读”; }否则{ echo“不可读!”
;//echo“不可读!” } 如果(可写($file)){ 回声“可写”; }否则{ echo“不可写!”
;//echo“不可读!” } $handle=fopen(“personals.txt”,“r+”,TRUE);
以下是最后的PHP错误消息:

警告:fopen(personals.txt)[function.fopen]:无法打开流:第145行的/home/content/b/u/r/burtsweeto/html/adrenimport.php中没有这样的文件或目录 数组(4){[“type”]=>int(2)[“message”]=>string(118)”fopen(personals.txt)[function.fopen]:无法打开流:没有这样的文件或目录“[“file”]=>string(56)”/home/content/b/u/r/burtsweeto/html/adrenimport.php”[“line”]=>int(145)}

最后,我尝试将文件放在运行PHP脚本的目录中;而且它确实在那里正确地工作!我只是想通过在导入之前不必上传一个大文件来尽量减少最终用户持续的头痛


有没有我没有尝试过的建议?

将完整路径添加到
$file
,如下所示:

$file = "C:\\SWSRE\\Individuals.txt"; 

set\u包括路径()
ini\u set()
做它们听起来像什么;它们调整包含路径,这与所有路径不同
file_exists()
需要一个绝对路径或一个相对于调用它的PHP文件的路径。它不受
set\u include\u path()
ini\u set('safe\u mode\u include\u dir',…)

什么是文件权限?
file\u exists()
不考虑include path。在wordpress站点中也存在同样的问题。fopen()仅当且仅当文件与从中调用fopen的functions.php文件位于同一目录下时才会打开文件。我以前尝试过,现在又尝试过。关于is_readable()和is_writeable(),它仍然会给我相同的错误。(@ShivanRaptor)至于权限,由于该文件位于我作为管理员登录的本地计算机上,这不考虑文件权限吗?