You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

本地正常的QR-Code Generator在虚拟主机上无法运行求助

Troubleshooting QR Code Generation on Shared Hosting

Hey there! I’ve run into similar headaches with PHP QR code libraries on shared hosts before—let’s walk through the most common fixes to get your code working:

1. Check for Missing PHP Extensions

The endroid/qr-code library depends on image processing extensions to generate QR codes. The two most critical ones are GD and Imagick.

  • Open your phpinfo page and search for gd or imagick to confirm if either is enabled.
  • If neither shows up, reach out to your hosting provider to enable one of them (many shared hosts let you toggle extensions via tools like cPanel’s PHP Selector).

2. Verify File Permissions

Even though you’re using writeString() to output the QR code as a string, the library might still attempt to write temporary files in the background.

  • Ensure the directory holding your script has proper permissions: set directories to 755 and files to 644 (standard safe defaults for shared hosting).
  • If you’re storing generated images anywhere, double-check that directory’s write permissions too.

3. Match PHP Versions Between Local and Host

Mismatched PHP versions are a frequent culprit. The endroid/qr-code library has strict version requirements—for example, newer releases need PHP 7.4 or higher.

  • Compare your local PHP version with the one on your host (you can find this in phpinfo).
  • If your host’s PHP is older, either upgrade it via your hosting control panel or downgrade the library to a version compatible with your host’s PHP.

4. Enable Error Reporting for Concrete Details

Right now you’re guessing at the issue—let’s get specific error messages. Add these lines at the very top of your script:

error_reporting(E_ALL);
ini_set('display_errors', 1);

When you load the page again, you’ll see exactly what’s failing (like "Call to undefined function imagecreatefromstring()" if GD is missing, or permission errors). This will save you tons of trial-and-error time.

5. Test a Simplified QR Code Output

To rule out issues with imagecopy or your existing image manipulation code, try generating just the QR code in isolation:

$qrCode = new QrCode($fullsku);
$qrCode->setSize($qrCodeSize);
$qrCode->setMargin(0);
$qrCode->setEncoding('UTF-8');

header('Content-Type: image/png');
echo $qrCode->writeString();
exit;

If this displays a working QR code, the problem isn’t with the library itself—it’s in how you’re integrating it with your existing image ($im). You can then debug the imagecopy step separately.


内容的提问来源于stack exchange,提问作者tonigiri

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:53:28