CodeIgniter Forums
problems with file_exists() - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: problems with file_exists() (/thread-37851.html)



problems with file_exists() - El Forum - 01-22-2011

[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.


problems with file_exists() - El Forum - 01-22-2011

[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');


problems with file_exists() - El Forum - 01-22-2011

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


problems with file_exists() - El Forum - 01-22-2011

[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!


problems with file_exists() - El Forum - 01-22-2011

[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



problems with file_exists() - El Forum - 01-22-2011

[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