0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

QRコード

Posted at
use ZipArchive;
use Illuminate\Support\Facades\Storage;

public function createAndDownloadZip()
{
    // ZipArchiveを作成してzipファイルを開きます
    $zip = new ZipArchive;
    $zipFileName = 'archive.zip';
    $zipFilePath = storage_path('app/work/' . $zipFileName);

    if ($zip->open($zipFilePath, ZipArchive::CREATE | ZipArchive::OVERWRITE) === TRUE) {
        // QRコードのデータ
        $qrCodeData = 'https://example.com';

        // QRコードをjpgファイルとして作成して直接zipに追加します
        $qrCodeFileName = 'qrcode.jpg';
        $qrCodeFileContents = QrCode::format('jpg')->size(200)->generate($qrCodeData);
        $zip->addFromString($qrCodeFileName, $qrCodeFileContents);

        // アーカイブを閉じます
        $zip->close();

        // レスポンスとしてzipファイルをダウンロードします
        return response()->download($zipFilePath)->deleteFileAfterSend(true);
    } else {
        // アーカイブを作成できない場合の処理
        return response('アーカイブを作成できませんでした', 500);
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?