ballhogjoni Posted October 2, 2008 Share Posted October 2, 2008 do you have to have an absolute path to the file for this function to work or can you have http://www.example.com? ex: file_exists(/absolute/path) or file_exists(http://www.example.com) Link to comment https://forums.phpfreaks.com/topic/126708-files_exists-question/ Share on other sites More sharing options...
trq Posted October 2, 2008 Share Posted October 2, 2008 Depends on whether or not you have url wrappers enabled. In most cases (shared hosting) you will require an absolute filesystem path. Link to comment https://forums.phpfreaks.com/topic/126708-files_exists-question/#findComment-655353 Share on other sites More sharing options...
ballhogjoni Posted October 2, 2008 Author Share Posted October 2, 2008 Thorpe, thx, noob question: I am not familiar with the term "filesystem path", is that another term for absolute path? Link to comment https://forums.phpfreaks.com/topic/126708-files_exists-question/#findComment-655355 Share on other sites More sharing options...
redarrow Posted October 2, 2008 Share Posted October 2, 2008 use php.net for refrences ok mate.......... file_exist needs the server path.......... <?php $filename = '/path/to/foo.txt'; if (file_exists($filename)) { echo "The file $filename exists"; } else { echo "The file $filename does not exist"; } ?> useing headers can see if the file exist via a full external url... <?php $file = 'http://www.domain.com/somefile.jpg'; $file_headers = @get_headers($file); if($file_headers[0] == 'HTTP/1.1 404 Not Found') { $exists = false; } else { $exists = true; } ?> Link to comment https://forums.phpfreaks.com/topic/126708-files_exists-question/#findComment-655356 Share on other sites More sharing options...
trq Posted October 2, 2008 Share Posted October 2, 2008 I am not familiar with the term "filesystem path", is that another term for absolute path? Yeah sorry, my bad. You could probably lose the filesystem part. use php.net for refrences ok mate.......... maybe you ought take your own medicine. file_exists() works perfectly well given a url providing the correct wrappers are installed and enabled. Link to comment https://forums.phpfreaks.com/topic/126708-files_exists-question/#findComment-655359 Share on other sites More sharing options...
corbin Posted October 2, 2008 Share Posted October 2, 2008 redarrow, the path does not have to be absolute. Link to comment https://forums.phpfreaks.com/topic/126708-files_exists-question/#findComment-655361 Share on other sites More sharing options...
ballhogjoni Posted October 2, 2008 Author Share Posted October 2, 2008 thx, all that being said I have the following code that does not work. I am on shared hosting so I don't know which wrappers are on and which ones are off (is there a way to tell?). $flag_image = ABSOLUTE_PATH."public_html/xxxxxx/articles/images/flags/". $myrow['flag']. ".gif"; echo $flag_image; if (file_exists($flag_image)) { $size = getimagesize($flag_image); echo " <img src='" . FACS_href . "articles/images/flags/" . $myrow['flag']. ".gif' " . $size[3] . " alt=''/>"; } the script will echo the $flag_image but the script dies after that, I assume this means that file_exists is not working correctly. Any advice? Link to comment https://forums.phpfreaks.com/topic/126708-files_exists-question/#findComment-655368 Share on other sites More sharing options...
redarrow Posted October 2, 2008 Share Posted October 2, 2008 how do u set it to not be absolte then......... file_exists(http://www.example.com) << what do u enable to get the correct result...... all ive read is use file_get_contents() <<<<< use that as what i can read ........ please advise me then sorry everyone.............. Link to comment https://forums.phpfreaks.com/topic/126708-files_exists-question/#findComment-655372 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.