Current Location: Home> Latest Articles> How to Generate Bulk QR Codes with PHP

How to Generate Bulk QR Codes with PHP

M66 2025-10-06

Use Cases for Bulk QR Code Generation with PHP

With the widespread adoption of QR codes, they have become a crucial tool for information sharing and quick scanning. In industries such as e-commerce, ticketing, and event management, there is often a need to generate large numbers of QR codes. Manually creating them is inefficient, so using PHP to automate the process is a practical solution.

Using the PHP QR Code Library

To generate QR codes, we can use the open-source PHP QR Code library. It allows developers to easily create static QR code images that can be integrated into various applications. All you need to do is download and include the library in your PHP project.

PHP Code Example for Bulk QR Code Generation

<?php
require('phpqrcode/qrlib.php');

$quantity = 100; // Number of QR codes to generate
$path = './qrcodes/'; // Directory to save QR codes

// Create directory if it doesn't exist
if(!is_dir($path)){
    mkdir($path, 0777, true);
}

for($i = 1; $i <= $quantity; $i++){
    $data = "https://example.com/qrcode/{$i}"; // QR code content
    $filename = $path . "qrcode_{$i}.png"; // File name for QR code

    // Generate QR code
    QRcode::png($data, $filename, QR_ECLEVEL_L, 8, 2);
    echo "QR Code {$i} generated successfully!<br>";
}

echo "Bulk QR code generation completed!";
?>

Code Explanation

In this example:

  • require includes the PHP QR Code library.
  • $quantity defines how many QR codes will be generated.
  • $path sets the directory where the codes will be stored, creating it if it does not exist.
  • The for loop generates each QR code, assigning unique content and filenames.
  • QRcode::png is the function that generates the QR code, where parameters control error correction level, size, and margin.

Output

After running the code, you will find 100 QR code image files in the qrcodes directory, named qrcode_1.png through qrcode_100.png. The browser will also display success messages during generation.

Conclusion

This tutorial shows how to use the PHP QR Code library to generate QR codes in bulk. Developers can extend the script to fetch data from a database, customize the QR code contents, or apply styling for better presentation. This method significantly improves efficiency when handling large-scale QR code generation.