From 12de4999a9e8440f1af371c63ae5f31e77ee566f Mon Sep 17 00:00:00 2001 From: themohooks <81331307+themohooks@users.noreply.github.com> Date: Thu, 10 Oct 2024 18:38:14 +0300 Subject: [PATCH] some fixes --- app/Controllers/Api/Images/Compress.php | 15 +++++++++++++-- app/Services/Upload.php | 1 - static/js/act.js | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/Controllers/Api/Images/Compress.php b/app/Controllers/Api/Images/Compress.php index d299b10..34f4ce0 100644 --- a/app/Controllers/Api/Images/Compress.php +++ b/app/Controllers/Api/Images/Compress.php @@ -14,7 +14,6 @@ class Compress { $height = $info[1]; $aspect_ratio = $width / $height; - // Вычисляем новые размеры, сохраняя соотношение сторон if ($width > $height) { $new_width = $max_width; $new_height = $max_width / $aspect_ratio; @@ -64,10 +63,22 @@ class Compress { $quality = 40; $max_width = 400; $max_height = 400; + if (!file_exists($_SERVER['DOCUMENT_ROOT'].'/cdn/imgcache')) { mkdir($_SERVER['DOCUMENT_ROOT'].'/cdn/imgcache', 0777, true); } + $parsed_url = parse_url($source_url); + if (!isset($parsed_url['scheme'])) { + $local_file_path = $_SERVER['DOCUMENT_ROOT'] . '/' . ltrim($source_url, '/'); + if (file_exists($local_file_path)) { + $source_url = $local_file_path; + } else { + header("HTTP/1.0 404 Not Found"); + exit; + } + } + $cache_filename = self::generateCacheFilename($source_url, $quality, $max_width, $max_height); if (file_exists($cache_filename)) { @@ -78,7 +89,7 @@ class Compress { if ($compressed_image_data) { file_put_contents($cache_filename, $compressed_image_data); } else { - $imageData = file_get_contents($_GET['url']); + $imageData = file_get_contents($source_url); $finfo = new \finfo(FILEINFO_MIME_TYPE); $mimeType = $finfo->buffer($imageData); diff --git a/app/Services/Upload.php b/app/Services/Upload.php index d4eaf49..92012d4 100644 --- a/app/Services/Upload.php +++ b/app/Services/Upload.php @@ -46,7 +46,6 @@ class Upload if (filesize($_SERVER['DOCUMENT_ROOT'].'/'.$location.$filecdn) >= 94371840) { mkdir("{$_SERVER['DOCUMENT_ROOT']}/uploads/{$location}", 0777, true); move_uploaded_file ($tmpname, "{$_SERVER['DOCUMENT_ROOT']}/uploads/{$folder}"); - $this->type = $type; $this->src = "/uploads/{$folder}"; $this->size = self::human_filesize(filesize($tmpname)); diff --git a/static/js/act.js b/static/js/act.js index cc7b3c2..c026f9f 100644 --- a/static/js/act.js +++ b/static/js/act.js @@ -9,7 +9,7 @@ function createModal(id, type, value, modalid) {
-   Ctrl + Enter +   Ctrl + Enter