Jump to content

A little help here please


joaomn

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/291869-a-little-help-here-please/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.