[英]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.