From 192fc2f45c29a7817b517a2dad4b5a659d26aede Mon Sep 17 00:00:00 2001 From: Snowz <372492339@qq.com> Date: Fri, 23 May 2025 20:27:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=9B=BE=E5=83=8F?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E7=B3=BB=E7=BB=9F=E4=BB=A5=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E8=BF=9C=E7=A8=8B=E5=9B=BE=E7=89=87=E5=8A=A0=E8=BD=BD=E6=80=A7?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增img.php文件,旧版本文件,一个开源项目的原始文件。 --- img.php | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 img.php diff --git a/img.php b/img.php new file mode 100644 index 0000000..bea60b4 --- /dev/null +++ b/img.php @@ -0,0 +1,69 @@ + 'image/gif', + 'jpeg' => 'image/jpeg', + 'jpg' => 'image/jpeg', + 'jpe' => 'image/jpeg', + 'png' => 'image/png', + 'webp' => 'image/webp', + ); + $type = $types[$ext] ? $types[$ext] : 'image/jpeg'; + + header("Content-type: ".$type); + + // 缓存图片 + $cacheDir = 'cache'; // 缓存文件夹 + + // 根据被缓存的网址创建文件夹 + $parsedUrl = parse_url($url); + $domain = $parsedUrl['host']; + $cacheSubDir = $cacheDir . '/' . $domain; + if (!file_exists($cacheSubDir)) { + mkdir($cacheSubDir, 0777, true); // 创建缓存子文件夹 + } + + // 获取原始图片名称 + $imageName = basename($url); + + $cachedImagePath = $cacheSubDir . '/' . $imageName; // 缓存图片路径 + + if (file_exists($cachedImagePath)) { + // 返回缓存图片 + readfile($cachedImagePath); + } else { + // 保存原始图片内容到缓存文件夹 + file_put_contents($cachedImagePath, $data); + + // 输出原始图片 + echo $data; + } +} +?> \ No newline at end of file