unistake Posted October 20, 2010 Share Posted October 20, 2010 Hi all, I want to make a script that identifies if an image JPG file exists. Would somthing like this work? <?php $file = "images/image.jpg"; if ($file > 0) { echo "file exists"; } else { echo "no file"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/216405-does-a-file-exist/ Share on other sites More sharing options...
ram4nd Posted October 20, 2010 Share Posted October 20, 2010 http://php.net/manual/en/function.file-exists.php SO <?php $filename = '/path/to/foo.txt'; if (file_exists($filename)) { echo "The file $filename exists"; } else { echo "The file $filename does not exist"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/216405-does-a-file-exist/#findComment-1124562 Share on other sites More sharing options...
rwwd Posted October 20, 2010 Share Posted October 20, 2010 [EDIT] I should learn to type quicker ;p $yourfile = "something.jpg"; if(file_exists($yourfile)){ //case true //do stuff } else{ //case false //show error message } There ya go! Rw Quote Link to comment https://forums.phpfreaks.com/topic/216405-does-a-file-exist/#findComment-1124565 Share on other sites More sharing options...
phpfreak Posted October 20, 2010 Share Posted October 20, 2010 you more than likely want to use $yourfile = '/path/to/something.jpg'; Use the full system path to the file to prevent issues with the file_exists function results. Quote Link to comment https://forums.phpfreaks.com/topic/216405-does-a-file-exist/#findComment-1124567 Share on other sites More sharing options...
unistake Posted October 20, 2010 Author Share Posted October 20, 2010 Thanks works well. Quote Link to comment https://forums.phpfreaks.com/topic/216405-does-a-file-exist/#findComment-1124576 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.