Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.67 KB | None | 0 0
  1.      /**
  2.      * Gets file contents by URL (uses 'file_get_contents()' if 'allow_url_fopen' enabled, cUrl is not)
  3.      * you should have cUrl installed or 'allow_url_fopen' enabled
  4.      * @param   $url        file url string
  5.      * @return  String      file contents
  6.      */
  7.     public static function getUrlContents($url)
  8.     {
  9.         # use cURL if 'allow_url_fopen' is disabled
  10.         if(ini_get('allow_url_fopen'))
  11.         {
  12.             $result = file_get_contents($url);
  13.         }else{
  14.             $ch = curl_init();
  15.             curl_setopt($ch, CURLOPT_URL, $url);
  16.             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  17.             curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
  18.             $result = curl_exec($ch);
  19.             curl_close($ch);
  20.         }
  21.                
  22.         return $result;
  23.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement