[英]i am generating qr code to browser how do i save that to a folder in php
我用这段代码来保存图像文件。 但它返回一个空文件。
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');
您的服务器是否已打开allow_url_fopen ?
如果是这样,使用file_get_contents和file_put_contents非常简单:
$in = file_get_contents('http://example.com/image.php');
file_put_contents('file.png', $in);
如果没有,你将不得不使用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');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.