Exemple #1
0
 public static function download($url, $timeout = 3000)
 {
     xapp_import('xapp.Commons.Error');
     xapp_import('xapp.Utils.Strings');
     xapp_import('xapp.Http.MiniHTTP');
     xapp_import('xapp.Directory.Utils');
     xapp_import('xapp.File.Utils');
     if (!$url) {
         return new XApp_Error('http_no_url', 'Invalid URL Provided.');
     }
     $tmpfname = XApp_Directory_Utils::tempname($url);
     if (!$tmpfname) {
         return new XApp_Error_Base('http_no_file', 'Could not create Temporary file.');
     }
     $http = new XApp_Http();
     $response = $http->request($url, array('timeout' => $timeout, 'stream' => true, 'filename' => $tmpfname));
     /*xapp_clog($response);*/
     if (XApp_Error_Base::is_error($response)) {
         unlink($tmpfname);
         return $response;
     }
     /*
     		if ( 200 != self::remote_retrieve_response_code( $response ) ){
     			unlink( $tmpfname );
     			return self::remote_retrieve_response_message( $response );
     		}*/
     $content_md5 = self::remote_retrieve_header($response, 'content-md5');
     if ($content_md5) {
         $md5_check = XApp_File_Utils::verify_file_md5($tmpfname, $content_md5);
         if (XApp_Error::is_error($md5_check)) {
             unlink($tmpfname);
             return $md5_check;
         }
     }
     return $tmpfname;
 }