Posted By

o0110o on 10/20/12


Tagged

curl php function files


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

o0110o


A function to see if a file exists with curl.


 / Published in: PHP
 

This function will use curl to see if a file exists at the location it's provided. It accepts $_path as a parameter.

  1. function file_alive($_path) {
  2. $handle = curl_init($_path);
  3. if (false === $handle) {return false;}
  4. curl_setopt($handle, CURLOPT_HEADER, false);
  5. curl_setopt($handle, CURLOPT_FAILONERROR, true);
  6. curl_setopt($handle, CURLOPT_HTTPHEADER, Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") ); // request as if Firefox because some sites request a valid header from you
  7. curl_setopt($handle, CURLOPT_NOBODY, true);
  8. curl_setopt($handle, CURLOPT_RETURNTRANSFER, false);
  9. $alive = curl_exec($handle);
  10. curl_close($handle);
  11. return $alive;
  12. }

Report this snippet  

You need to login to post a comment.