簡體   English   中英

如何將生成的二維碼保存到laravel?

[英]How to save generated qr Code in laravel?

我使用“simplesoftwareio/simple-qrcode”生成了二維碼: https://github.com/SimpleSoftwareIO/simple-qrcode

現在我想將生成的圖像保存在我的本地驅動器中。 我該怎么做?

 public function qr($id)
{

    $data = Ticket::get()->find($id);
    $image = \QrCode::format('png')
                     ->merge('img/t.jpg', 0.1, true)
                     ->size(200)->errorCorrection('H')
                     ->generate('A simple example of QR code!');
    return response($image)->header('Content-type','image/png');

    return view('qrCode', compact('qrData', $qrData));
}

你可以試試

$image = \QrCode::format('png')
                 ->merge('img/t.jpg', 0.1, true)
                 ->size(200)->errorCorrection('H')
                 ->generate('A simple example of QR code!');
$output_file = '/img/qr-code/img-' . time() . '.png';
Storage::disk('local')->put($output_file, $image); //storage/app/public/img/qr-code/img-1557309130.png

你可以為公眾嘗試這個

Storage::disk('public')->put($output_file, $image); //storage/app/public/img/qr-code/img-1557309130.png
$data = new ModelName();

$path = '/img/qr-code/img/';

if(!\File::exists(public_path($path))) {
    \File::makeDirectory(public_path($path));
}

$file_path = $path . time() . '.png';
$image = \QrCode::format('png')
                 ->merge('img/t.jpg', 0.1, true)
                 ->size(200)->errorCorrection('H')
                 ->generate('A simple example of QR code!', $file_path)

$data->field_name = $file_path;
$data->save();

I hope this will help you, it works fine for me

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM