Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downloading file programmatically with HTTP authentication [closed]

I want to download a file (e.g. http://rapidpich.ir/d/555864) programmatically using php. However, when I attempt to follow the link in my web browser, I'm asked for a username and password.

How can I provide these credentials in PHP and retrieve the file?

Authentication dialog in Windows

like image 269
soo Avatar asked Dec 01 '25 14:12

soo


1 Answers

Usually to grab a file you'd write something like:

$file_contents = file_get_contents("http://url.to/file");

You may do something other than store into a variable, or you may use a different function.

If the file is protected by HTTP authentication, you can usually specify the credentials in the URI:

$file_contents = file_get_contents("http://username:[email protected]/file");

Hope this helps.

like image 52
Lightness Races in Orbit Avatar answered Dec 03 '25 04:12

Lightness Races in Orbit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!