using php Download File From a given URL by passing username and password for http authentication
- by Acharya
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!!!