pixelfed-imgproxy-apache2/imgproxy/index.php

16 lines
538 B
PHP
Raw Normal View History

2020-10-08 13:18:48 +00:00
<?php
$url = trim($_GET['url']);
# check url matches a https://domain/storage/whatever.jpeg url for images
2020-10-12 20:50:58 +00:00
if (preg_match('/^https:\/\/[^\/]+\/storage\/[^\s\%]+\.(png|jpg|jpeg)(\?v=[^\&])?$/', $url) ||
preg_match('/^https:\/\/[^\/]+\/system\/media_attachments\/[^\s\%]+\.(png|jpg|jpeg)(\?v=[^\&])?$/', $url)) {
2020-10-08 13:18:48 +00:00
if (preg_match('/^.*\.png(\?v=[^\&])?$/', $url))
header('Content-Type: image/png');
else if (preg_match('/^.*\.(jpg|jpeg)(\?v=[^\&])?$/', $url))
header('Content-Type: image/jpeg');
echo file_get_contents($url);
}
?>