Error with downloading of file with PHP
I use easy script for downloading file from Internet:
$file=file_get_contents("url");
file_put_contents('temp.flv', $file);
It is good works on my local server, but when I put it on my Internet server my script didn't work with error message:
"failed to open stream: HTTP request failed! HT开发者_如何学JAVATP/1.1 403 Forbidden in /home/virtwww/w_dennyboy-ru_d5bd1633/http/index.php"
I try to use it on a few servers, but it is doesn't work always. I try to use 'copy' function too. Help me please.
It sounds like allow_url_fopen
is disabled on the remote servers (which is basically standard). I would recommend using curl instead; which is what it is built for. Something like this should work:
$url = 'http://example.com';
$fileOut = '/var/www/file.test';
$fh = fopen($fileOut, 'w');
//Create curl resource and execute
$curl = curl_init();
curl_setopt($curl, CURLOPT_FILE, $fh);
curl_setopt($curl, CURLOPT_URL, $url);
curl_exec($curl);
curl_close($curl);
fclose($fh);
精彩评论