joaomn Posted October 16, 2014 Share Posted October 16, 2014 Hello, i dont know much coding, basically i go on the internet and grab a piece here and there, and get it all together, but this is not working for me and i need your help, where´s the error here? Code <?php $file = 'http://' . $_SERVER['HTTP_HOST']. '/file.txt'; if (!file_exists($file)) {echo "<div align=\"center\"><h1>Missing file!</h1></div>";} ?> Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/291869-a-little-help-here-please/ Share on other sites More sharing options...
QuickOldCar Posted October 16, 2014 Share Posted October 16, 2014 Your snippet works for me. Missing file! Quote Link to comment https://forums.phpfreaks.com/topic/291869-a-little-help-here-please/#findComment-1493939 Share on other sites More sharing options...
Frank_b Posted October 16, 2014 Share Posted October 16, 2014 I think file_exists() is not designed for URL's but from PHP 5 it will work with some url wrappers. try this one too: $filename= 'https://www.google.pl/logos/2012/haring-12-hp.png'; $file_headers = @get_headers($filename); if($file_headers[0] == 'HTTP/1.0 404 Not Found'){ echo "The file $filename does not exist"; } else if ($file_headers[0] == 'HTTP/1.0 302 Found' && $file_headers[7] == 'HTTP/1.0 404 Not Found'){ echo "The file $filename does not exist, and I got redirected to a custom 404 page.."; } else { echo "The file $filename exists"; } source: http://stackoverflow.com/questions/10444059/file-exists-returns-false-even-if-file-exist-remote-url Quote Link to comment https://forums.phpfreaks.com/topic/291869-a-little-help-here-please/#findComment-1493940 Share on other sites More sharing options...
joaomn Posted October 19, 2014 Author Share Posted October 19, 2014 I will try that Frank_b, QuickOldCar, it does not work, it always returns the same value, at least for me... Thank you guys, will update upon testing. Quote Link to comment https://forums.phpfreaks.com/topic/291869-a-little-help-here-please/#findComment-1494137 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.