PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hello everyone
I need a function/code/a hint in the right direction as to finding out if an image resides of the server that I'm running my php code from. Could I just use fopen() to check if it was there, or is there a better way?
Thanks in advance
-wyrmmage
file_exists() check if is it really a file, but make not distintion between file types.
For example if you "feed" the funtion with only a directory path it will return TRUE if the directory exists.
So you may create a funtion that returns true if it find the file type you want as on the example below
the file_exists() function + Pearl style pattern match
If you want to match the file extension, you could just use pathinfo(). But that doesn't really tell you if it's an image, since you could rename a .exe to .jpg. getimagesize() actually pulls the first few bytes of the file and checks it against known file formats.