file_exists returns False even the existing file

-1

In the system I am using file_exists to see if the image exists in the directory, the problem is that it always returns false even the image existing in the directory, I have already done almost all possible tests and still returns false .

Code:

<?php    
  $Image = "http://megaki/uploads/windows/173/1731534093656.jpeg";

if (file_exists($Image)) {
echo "O arquivo $Image existe";
} else {
echo "O arquivo $Image não existe";
}
?>

When running, returns the message:

O arquivo http://megaki/uploads/windows/173/1731534093656.jpeg não existe

The directory is correct when I create the directory I give permission 077 and even then I can not resolve it I am already 2 days trying to solve it and I can not.

    
asked by anonymous 12.08.2018 / 19:30

1 answer

1

Generally, file_exists is used to test the existence of a physical file, not an address as an http resource.

In your case, it seems to me that you are trying to check whether a file that is in a directory of your project exists or not. In this case, use the physical path of the file on your server to verify.

So:

define('ROOT_DIR', 'diretório/raiz/do/projeto');

$file = ROOT_DIR . '/uploads/windows/173/1731534093656.jpeg';

var_dump(file_exists($file));

Tip

To discover the default project folder automatically, I recommend using the __DIR__ variable.

In my applications, I usually use only index.php , so I do not usually have problems with this constant by varying the value by using a script in another folder, for example.

    
12.08.2018 / 21:14