CodeIgniter Forums

Full Version: problems with file_exists()
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Piatra[/eluser]
im having some trouble with the function file_exists(). it returns false even though the file exists eg.
Code:
if(file_exists($file)) echo "<img >"
wouldnt echo anything, but if i copy paste the url in the address bar it works. is it my coding ? i did use the base_url() function to make sure the path is always correct.

El Forum

[eluser]Mike DeFelice[/eluser]
I believe file_exists needs to use the relative path on the hard drive. For instance file_exists('./images/example.jpg');

El Forum

[eluser]Piatra[/eluser]
funny thing is it works for some paths

El Forum

[eluser]Mike DeFelice[/eluser]
I think I was confused, I thought you tried doing file_exists('http://www.example.com/test.jpg'); sorry about that!

El Forum

[eluser]Piatra[/eluser]
[quote author="Mike DeFelice" date="1295756196"]I think I was confused, I thought you tried doing file_exists('http://www.example.com/test.jpg'); sorry about that![/quote]

This is an example path
Code:
http://localhost/website/upload/1295355758768_thumb.jpg

El Forum

[eluser]Mike DeFelice[/eluser]
file_exists() seems to only work for files on your server, not being able to use urls as the path. You can use some sort of curl function to do this, there are a lot of examples on the php site.

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