1
0
Fork 0

Handle system proxy in file downloads

pull/184/head
Jordan Alliot 2012-01-05 11:40:11 +01:00
parent 21ab41fa2d
commit 1471b41ba8
1 changed files with 16 additions and 1 deletions

View File

@ -59,7 +59,22 @@ abstract class FileDownloader implements DownloaderInterface
} }
} }
// Handle system proxy
if (isset($_SERVER['HTTP_PROXY'])) {
// http(s):// is not supported in proxy
$proxy = str_replace(array('http://', 'https://'), array('tcp://', 'ssl://'), $_SERVER['HTTP_PROXY']);
$ctx = stream_context_create(array(
'http' => array(
'proxy' => $proxy,
'request_fulluri' => true,
),
));
copy($url, $filename, $ctx);
} else {
copy($url, $fileName); copy($url, $fileName);
}
if (!file_exists($fileName)) { if (!file_exists($fileName)) {
throw new \UnexpectedValueException($url.' could not be saved to '.$fileName.', make sure the' throw new \UnexpectedValueException($url.' could not be saved to '.$fileName.', make sure the'