开发者

Downloading file programmatically with HTTP authentication [closed]

开发者 https://www.devze.com 2023-02-24 08:19 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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?

Downloading file programmatically with HTTP authentication [closed]


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

0

精彩评论

暂无评论...
验证码 换一张
取 消