i used this code to save image file. but its returning an empty file .
function save_from_url($inPath,$outPath) {
$in= fopen($inPath, "rb");
$out= fopen($outPath, "wb");
while ($chunk = fread($in,8192))
{
fwrite($out, $chunk, 8192);
}
fclose($in);
fclose($out);
}
save_from_url('url/eg.php','flw.png');
Does your server have allow_url_fopen turned on?
If it does, using file_get_contents and file_put_contents is quite simple:
$in = file_get_contents('http://example.com/image.php');
file_put_contents('file.png', $in);
If not, you will have to use cURL :
$in = curl_init('http://example.com/image.php');
$out = fopen('file.png', 'wb');
curl_setopt($in, CURLOPT_FILE, $out);
curl_setopt($in, CURLOPT_HEADER, 0);
curl_exec($in);
curl_close($in);
fclose($out);
或者只是从远程URL复制它:
copy('http://www.google.com/images/srpr/logo11w.png', '/tmp/google.png');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.