using php Download File From a given URL by passing username and password for http authentication
Posted
by Acharya
on Stack Overflow
See other posts from Stack Overflow
or by Acharya
Published on 2010-04-30T06:18:32Z
Indexed on
2010/04/30
6:27 UTC
Read the original article
Hit count: 198
Hi all,
I need to download a text file using php code. The file is having http authentication. What procedure I should use for this. Should I use fsocketopen or curl or Is there any other way to do this?
I am using fsocketopen but it does not seem to work.
$fp=fsockopen("www.example.com",80,$errno,$errorstr);
$out = "GET abcdata/feed.txt HTTP/1.1\r\n";
$out .= "User: xyz \r\n";
$out .= "Password: xyz \r\n\r\n"; fwrite($fp, $out);
while(!feof($fp)) {
echo fgets($fp,1024);
}
fclose($fp);
Here fgets is returning false.
Any help!!!
© Stack Overflow or respective owner