Пример #1
0
 public static function downloadUrl($url, $path, $name)
 {
     if (empty($url)) {
         throw new Exception('[ERROR] Class cron, function downloadUrl, $url is empty !');
     }
     if (empty($path)) {
         throw new Exception('[ERROR] Class cron, function downloadUrl, $path is empty !');
     }
     cron::message(sprintf("Class cron, function downloadUrl, de volgende url word aangeroepen: %s, naar %s/%s !", $url, $path, $name));
     if (!($fp = fopen($path . '/' . $name, 'w+'))) {
         //This is the file where we save the information
         cron::message(sprintf("Class cron, function downloadUrl, fopen error !"), 'error');
         fclose($fp);
         return false;
     }
     $ch = curl_init(str_replace(' ', '%20', $url));
     //Here is the file we are downloading, replace spaces with %20
     curl_setopt($ch, CURLOPT_TIMEOUT, 50);
     curl_setopt($ch, CURLOPT_FILE, $fp);
     // write curl response to file
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
     if (false === curl_exec($ch)) {
         cron::message(sprintf("Class cron, function downloadUrl, curl_exec error: %s", curl_error($ch)), 'error');
         // Close handle
         curl_close($ch);
         fclose($fp);
         return false;
     }
     // Close handle
     curl_close($ch);
     fclose($fp);
     return true;
 }