`<?php
// Get the requested image URL
$imageUrl = $_GET['url'];
// Define the cache directory where images will be stored
$cacheDir = '/path/to/cache/directory/';
// Generate a unique cache filename based on the requested image URL
$cacheFilename = md5($imageUrl) . '.jpg';
$cachePath = $cacheDir . $cacheFilename;
// Check if the image is already cached
if (file_exists($cachePath)) {
// Serve the cached image
header('Content-Type: image/jpeg');
readfile($cachePath);
} else {
// Fetch the image from the original server
$imageData = file_get_contents($imageUrl);
// Save the image to the cache directory
file_put_contents($cachePath, $imageData);
// Serve the fetched image
header('Content-Type: image/jpeg');
echo $imageData;
}
?>
`