The file_exists function does not work in php

I am trying to find file_exist file in a directory. If I do not want to use another image. But since I use the file_exists function, it always returns false.

Code used

while($r=mysql_fetch_row($res)) { if(!file_exists('http://localhost/dropbox/lib/admin/'.$r[5])) { $file='http://localhost/dropbox/lib/admin/images/noimage.gif'; } else $file='http://localhost/dropbox/lib/admin/'.$r[5];} 

But the function always returns false, even if the file exits. I checked this using

 <img src="<?php echo 'http://localhost/dropbox/lib/admin/'.$r[5]; ?>" /> 

This displayed the image correctly.

Please help me

+4
source share
6 answers

You are passing the url to the file_exists function, which is incorrect. Instead, pass the local folder path.

 while($r=mysql_fetch_row($res)) { if(!file_exists('/dropbox/lib/admin/'.$r[5])) { $file='/dropbox/lib/admin/images/noimage.gif'; } else $file='/dropbox/lib/admin/'.$r[5]; } 
0
source

file_exists uses file system paths, not URLs. You use the URLs in the browser to access your PHP scripts through the web browser and web server over the network. The PHP script itself can access the local file system and uses this; it does not go through the network stack to access files.

So use something like file_exists('C:\\foo\\bar\\dropbox\\lib\\admin\\' ...) .

+2
source

file_exists does not support addresses using HTTP (you can see this because stat not included in the list of wrappers supported via HTTP ). As the documentation of file_exists , deleted files can be checked using some shells, such as FTP, but this is not possible via HTTP, so file_exists will always return false.

Assuming this file is located on the local computer (as suggested by localhost , you need to access it using the local path to the file. It is hard to guess what it might be for you, but /var/www/dropbox... might seem.

0
source

file_exists() checks if a file exists on the local file system. You are passing the url. Change it to the local path to the Dropbox directory and it should work:

 if(file_exists('/path/to/your/dropbox')) 
0
source

The file_exists function can only work for URL protocols that are supported by the stat() function in PHP.

The http protocol is currently not supported by this shell.

http://uk3.php.net/manual/en/wrappers.http.php

0
source

You are passing the URL to the file_exists function, which is an invalid parameter. Instead, skip your local path.

To learn more about the file_exist () function, read this php manual:

http://php.net/manual/en/function.file-exists.php

0
source

All Articles