I need to download images from both http
and https
protocols via a web proxy. This proxy needs authentication (it requires username
and password
). How can I do that? Currently I use the copy
function of php to download files but I don't know how to set proxy for it. Thanks.
Asked
Active
Viewed 4,256 times
2

Alireza Noori
- 14,961
- 30
- 95
- 179
-
php-curl could be the solution http://stackoverflow.com/questions/9822211/proxy-authentication-required-with-curl – Alex Aug 09 '12 at 10:21
-
3[Google the exact title of your question](http://www.google.co.uk/search?q=php%3A+Download+files+from+URL+with+a+HTTPS+proxy) and look at the 4th result. – DaveRandom Aug 09 '12 at 10:24
-
To be clear, I want a **secure** connection. I have tried the `curl` option provided in the link but I got the same `403` error which I would get without the proxy. This proxy is supposed to bypass a filtering system. – Alireza Noori Aug 09 '12 at 12:42
-
Please review the edit. I have included new code. Thanks. – Alireza Noori Aug 09 '12 at 14:27
1 Answers
1
I solved my problem using this code:
public static function dlFile($url)
{
$crl = curl_init();
curl_setopt($crl, CURLOPT_PROXY, "IP:PORT");
curl_setopt($crl, CURLOPT_PROXYUSERPWD, "USER:PASS");
curl_setopt ($crl, CURLOPT_URL,$url);
curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, 300);
curl_setopt($crl, CURLOPT_HTTPPROXYTUNNEL, true); //IMPORTANT
$ret = curl_exec($crl);
curl_close($crl);
return $ret;
}

Alireza Noori
- 14,961
- 30
- 95
- 179