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.
H开发者_如何学JAVAow can I provide these credentials in PHP and retrieve the file?
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:password@url.to/file");
Hope this helps.
You can use cURL to submit form data.
Take a look here cURL tutorial and here php cURL
精彩评论