Remove Utils::download and Utils::getRemoteFileSize
This commit is contained in:
parent
cb7f4d9806
commit
4d8da4dce6
|
|
@ -35,69 +35,6 @@ class Utils
|
||||||
return is_request_secure();
|
return is_request_secure();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function download($url, $path)
|
|
||||||
{
|
|
||||||
@set_time_limit(0);
|
|
||||||
|
|
||||||
touch($path);
|
|
||||||
|
|
||||||
Log::info("[File Downloader] Download started, source: $url");
|
|
||||||
Log::info("[File Downloader] ======================================");
|
|
||||||
|
|
||||||
$context = stream_context_create(['http' => [
|
|
||||||
'method' => 'GET',
|
|
||||||
'header' => 'User-Agent: '.menv('USER_AGENT', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36')
|
|
||||||
]]);
|
|
||||||
|
|
||||||
if ($fp = fopen($url, 'rb', false, $context)) {
|
|
||||||
|
|
||||||
if (! $download_fp = fopen($path, 'wb')) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (! feof($fp)) {
|
|
||||||
|
|
||||||
if (! file_exists($path)) {
|
|
||||||
// Cancel downloading if destination is no longer available
|
|
||||||
fclose($download_fp);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Log::info('[File Downloader] 1024 bytes wrote');
|
|
||||||
fwrite($download_fp, fread($fp, 1024 * 8 ), 1024 * 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose($download_fp);
|
|
||||||
fclose($fp);
|
|
||||||
|
|
||||||
Log::info("[File Downloader] Finished downloading, data stored to: $path");
|
|
||||||
Log::info("[File Downloader] ===========================================");
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function getRemoteFileSize($url)
|
|
||||||
{
|
|
||||||
$regex = '/^Content-Length: *+\K\d++$/im';
|
|
||||||
|
|
||||||
if (! $fp = @fopen($url, 'rb')) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
isset($http_response_header) &&
|
|
||||||
preg_match($regex, implode("\n", $http_response_header), $matches)
|
|
||||||
) {
|
|
||||||
return (int)$matches[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
return strlen(stream_get_contents($fp));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get date time string in "Y-m-d H:i:s" format.
|
* Get date time string in "Y-m-d H:i:s" format.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user