mirror of
https://github.com/Ahwxorg/Binternet.git
synced 2026-03-11 08:54:37 +00:00
Update image_proxy.php
1. Add support for "pin.it". 2. Improved error handling with appropriate HTTP response codes and error messages. 3. Utilized `filter_var` for URL sanitization.
This commit is contained in:
parent
2bed56224f
commit
087003b134
1 changed files with 21 additions and 14 deletions
|
|
@ -1,19 +1,26 @@
|
|||
<?php
|
||||
|
||||
require "misc/tools.php";
|
||||
|
||||
$url = $_REQUEST["url"];
|
||||
$url = filter_var($_REQUEST["url"], FILTER_SANITIZE_URL);
|
||||
$requested_root_domain = get_root_domain($url);
|
||||
|
||||
$allowed_domains = array("pinimg.com", "i.pinimg.com", "pinterest.com");
|
||||
|
||||
if (in_array($requested_root_domain, $allowed_domains))
|
||||
{
|
||||
$image = $url;
|
||||
$image_src = request($image);
|
||||
|
||||
header("Content-Type: image/png");
|
||||
echo $image_src;
|
||||
$allowed_domains = array("pinimg.com", "i.pinimg.com", "pinterest.com", "pin.it");
|
||||
if (in_array($requested_root_domain, $allowed_domains)) {
|
||||
$image_src = request($url);
|
||||
if ($image_src !== false) {
|
||||
$finfo = new finfo(FILEINFO_MIME_TYPE);
|
||||
$mime_type = $finfo->buffer($image_src);
|
||||
if (strpos($mime_type, 'image/') === 0) {
|
||||
header("Content-Type: $mime_type");
|
||||
echo $image_src;
|
||||
} else {
|
||||
header("HTTP/1.1 415 Unsupported Media Type");
|
||||
echo "Error: The requested URL does not contain a valid image.";
|
||||
}
|
||||
} else {
|
||||
header("HTTP/1.1 404 Not Found");
|
||||
echo "Error: Unable to fetch the image.";
|
||||
}
|
||||
} else {
|
||||
header("HTTP/1.1 400 Bad Request");
|
||||
echo "Error: Invalid domain.";
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
Loading…
Reference in a new issue