引入完整的App图标搜索器增强版,包括前端页面、后端缓存系统、样式和脚本。主要功能包括实时搜索、多尺寸图标下载、图片预览、响应式设计和智能缓存机制。后端通过ImageCache类实现图片缓存,前端通过JavaScript优化搜索交互和图片加载体验。新增README.md提供详细的部署和开发指南。
32 lines
887 B
PHP
32 lines
887 B
PHP
<?php
|
|
class ImageCache {
|
|
private $cacheDir;
|
|
private $cacheDuration = 604800; // 7天缓存
|
|
|
|
public function __construct() {
|
|
$this->cacheDir = __DIR__ . '/images/';
|
|
if (!file_exists($this->cacheDir)) {
|
|
mkdir($this->cacheDir, 0777, true);
|
|
}
|
|
}
|
|
|
|
public function getCachedImage($url) {
|
|
$cacheFile = $this->cacheDir . md5($url);
|
|
|
|
if (file_exists($cacheFile) && (time() - filemtime($cacheFile) < $this->cacheDuration)) {
|
|
return file_get_contents($cacheFile);
|
|
}
|
|
|
|
$imageContent = file_get_contents($url);
|
|
if ($imageContent !== false) {
|
|
file_put_contents($cacheFile, $imageContent);
|
|
return $imageContent;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function getCacheUrl($url) {
|
|
return 'cache/image.php?url=' . urlencode($url);
|
|
}
|
|
} |