当filename通过变量传递时,file_exists返回false

时间:2013-01-05 14:57:35

标签: php file wamp exists

我很难过,我确信我在这里遗漏了一些非常基本的东西。安全模式已禁用,文件存在。

此代码:

$dir = "textfiles"
chdir('../'.$dir."/");
  //using a Windows Slash here(Wamp Stack, on Windows 7 Dev environment

$filename = getcwd() ."\\". $row[0];

       //echoing this outputs: 
       //C:\wamp\www\wordpress\textfiles\New Text Document.txt


$filename = str_replace("\\","\\\\",$filename);

      //echoing this outputs C:\\wamp\\www\\wordpress\\textfiles\\New Text Document.txt
      //escaping slashes in filename to prevent escaping. I SUSPECT my issue may be
      // related to this

    //if (file_exists("C:\\wamp\\www\\wordpress\\textfiles\\New Text Document.txt")) {
            //Line above is commented out, but when it replaces the line below, this thing                       
            //returns True


if (file_exists($filename)) {echo "Yes";} 
   else { echo $filename;}

1 个答案:

答案 0 :(得分:0)

注释掉

/* $filename = str_replace("\\","\\\\",$filename); */

您的代码应该有效。