Siteβ―Builder
Editing:
qr-proxy.php
writable 0666
<?php /********************************************************************** * qr-proxy.php β oneβfile QR cacher * ------------------------------------------------------------------- * Accepts ?data=<URLβencoded vCard> * Saves /social/<slug>/qr.png or /ph/<digits>/qr.png **********************************************************************/ /* 1. Basic sanity check ------------------------------------------------ */ if (empty($_GET['data'])) { http_response_code(400); exit('Missing ?data'); } $vcard = urldecode($_GET['data']); // make it readable /* 2. Derive absolute folder from decoded vCard ------------------------ */ $root = $_SERVER['DOCUMENT_ROOT']; // e.g. /var/www/html $profileDir = null; if (preg_match('#https?://[^/]+/(social|ph)/([A-Za-z0-9_]+)/?#i', $vcard, $m)) { $profileDir = "$root/{$m[1]}/{$m[2]}"; // e.g. /var/www/html/social/jane } if (!$profileDir) { http_response_code(400); exit('Could not find /social/β¦ or /ph/β¦ path in vCard'); } @mkdir($profileDir, 0775, true); // ensure folder exists (ignore if already) /* 3. Local + remote PNG paths ----------------------------------------- */ $localPng = $profileDir . '/qr.png'; $remoteUrl = 'https://api.qrserver.com/v1/create-qr-code/' . '?size=170x170&data=' . urlencode($_GET['data']); /* 4. Try to fetch a fresh PNG ----------------------------------------- */ $pngData = @file_get_contents($remoteUrl); // silent network errors $good = $pngData && strncmp($pngData, "\x89PNG", 4) === 0; if ($good) { // save new copy @file_put_contents($localPng, $pngData, LOCK_EX); } elseif (is_readable($localPng)) { // fallback to cache $pngData = file_get_contents($localPng); } else { // nothing to serve http_response_code(502); exit('QR service down & no cached image'); } /* 5. Send PNG to browser ---------------------------------------------- */ header('Content-Type: image/png'); header('Cache-Control: public, max-age=604800'); // 7Β days client cache echo $pngData;
Save changes
Create folder
writable 0777
Create
Cancel