【问题标题】:Trying to use khanamiryan's php-qrcode-detector-decoder on apache2 / php7尝试在 apache2 / php7 上使用 khanamiryan 的 php-qrcode-detector-decoder
【发布时间】:2019-09-14 20:42:42
【问题描述】:

我正在尝试使用 khanamiryan 的 php 库从图像文件中读取二维码; https://github.com/khanamiryan/php-qrcode-detector-decoder

目前我无法让它在 Debian Stretch(特别是 Raspberry Pi 3B 上的 Raspbian Stretch)上运行。我只能得到 HTTP 500 错误。

干净安装 Raspbian Stretch,然后在终端中执行以下操作;

sudo apt-get install apache2 php libapache2-mod-php php7.0-gd composer
cd /var/www/html
composer require khanamiryan/qrcode-detector-decoder

这是我要运行的 php;

<?php
require __DIR__ . "/vendor/autoload.php";
$qrcode = new QrReader('test.png');
$text = $qrcode->text();
print($text);
?>

预期结果是图像 test.png 中 QR 码的文本写入响应,但我总是收到 HTTP 500 错误。

有什么建议吗?我需要安装一些底层 C++ 或 Java 库吗?

【问题讨论】:

  • 您是否检查过 Web 服务器日志文件的输出(对于 apache2,通常位于 /var/log/apache2/error.log)。一般来说,您可以找到更多关于 PHP 脚本失败原因的信息...
  • 是的,我知道了;致命错误:未捕获的错误:在 /var/www/html/index.php:3 中找不到类 'QrReader' 堆栈跟踪:#0 {main} 在第 3 行的 /var/www/html/index.php 中抛出跨度>
  • 听起来您需要将 QrReader 添加到自动加载中,或者可能使用完整的命名空间作为类名。
  • 啊哈,进步了。我添加了use Zxing\QrReader; 行,现在我有这个错误输出(太长了,不适合这个评论)
  • 命名空间使用反斜杠,即:use Zxing\QrReader;

标签: php qr-code


【解决方案1】:

添加命名空间行use Zxing\QrReader;

<?php
use Zxing\QrReader;
require __DIR__ . "/vendor/autoload.php";
$qrcode = new QrReader('test.png');
$text = $qrcode->text();
print($text);
?>

在终端也运行这个

sudo apt-get install php7.0-mbstring

【讨论】:

    猜你喜欢
    • 2016-11-03
    • 1970-01-01
    • 1970-01-01
    • 2014-07-28
    • 2016-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-19
    相关资源
    最近更新 更多