file_exists does not find file

Asked

Viewed 428 times

1

I’m having a problem using the php function that checks if any file exists in a directory using file_exists but always returns false even if the file being in the directory someone would have a solution for it

$filename = 'http://megaki/uploads/windows/thumb.jpg';
     if (file_exists($filename)) {
         echo 'O arquivo existe no diretorio.';
          } else {
           echo 'O arquivo não existe nesse diretorio.';
              }

remembering the image exists in the windows directory but while running returns the message from Else that the file cannot be found I am using wampserver local

  • 1

    tried using $_SERVER[ 'DOCUMENT_ROOT' ] to get the absolute path of the file and see if it works that way?

  • thanks using the absolute path worked

  • That your link is weird wouldn’t be megaki.com?

1 answer

3


You Can Use the Magic Constant

__DIR__

(Return the path to the php file in which it is inserted) and walk to the path of the requested file. Example:

file_exists(__DIR__.'/caminho/para/o/arquivo');
  • that way it also worked

Browser other questions tagged

You are not signed in. Login or sign up in order to post.