chillerlan / php-qrcode

A PHP QR Code generator and reader with a user-friendly API.
https://smiley.codes/qrcode/
Apache License 2.0
2.01k stars 302 forks source link

Transfer of a file content to the render function #153

Closed Linuxmaker closed 2 years ago

Linuxmaker commented 2 years ago

Hello, Your tool is fantastic. However, I am looking for a way to transfer a file to the QRCode object instead of a string. The background is the bank QR code with 32 lines, the information for which is in the variable $data. $qrcode = (new QRCode($options))→render('https://www.google.com');

In the class definition QRCode.php it says from line 179:

public function render(string $data, string $file = null){
return $this->initOutputInterface($data)->dump($file);
}

How could this be changed so that a file with 32 lines of text can be passed instead?

Many greetings Linuxmaker

codemasher commented 2 years ago

Hey, what do you mean by "transfer a file to the QRCode"? Do you want the content of that file in the QRCode? In that case you would just fetch the content of that file via file_get_contents(), like so:

$qrcode = (new QRCode($options))->render(file_get_contents('/path/to/your/file.ext'));

The code snippet you posted manages the output of the finalized QRCode into a file.