file_exists() returns false, but the file DOES exist

后端 未结 14 1216
一向
一向 2020-12-05 09:40

I\'m having a very weird issue with file_exists(). I\'m using this function to check if 2 different files in the same folders do exist. I\'ve double-checked, they BOTH do ex

14条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-05 10:12

    I found that what works for me to check if a file exists (relative to the current php file it is being executed from) is this piece of code:

    $filename = 'myfile.jpg';
    $file_path_and_name = dirname(__FILE__) . DIRECTORY_SEPARATOR . "{$filename}";
    if ( file_exists($file_path_and_name) ){
      // file exists. Do some magic...              
    } else {
      // file does not exists...
    }
    

提交回复
热议问题