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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.