Auto redirect / download if image doesn't exist - optimisation

sufer

New Member
I have a lot of images on my website, they are pulled from an image server onto the main server when requested to save disk space at my hosting server.To achieve this I have an entry in my \[code\].htaccess\[/code\] file that basically internally redirects people from \[code\]/images/image.jpg\[/code\] to \[code\]download.php\[/code\] which checks to see if the file exists. If the file exists it serves it up (code below) else it'll use \[code\]CURL\[/code\] to pull in the remote file then redirect to itself \[code\]header("Location: ".$_SERVER['REQUEST_URI']);\[/code\] so that it then shows the image.Is it inefficient to serve images to the browser in such a manner? Is it faster to let the web server do it naturally? The code for reading and showing the file is below.\[code\]$file_extension = strtolower(substr(strrchr($filename,"."),1));header("Pragma: public");header("Content-Type: image/jpg");header("Content-length: ".filesize($filename));header("Content-Transfer-Encoding: binary");header("Content-Length: ".filesize($filename));readfile("$filename");\[/code\]Would I be better off (read: more efficient) NOT using a htaccess redirect but actually modifying my 404 page to check for image specific 404's and then download them?Here is the \[code\].htaccess\[/code\] that defines the redirect to \[code\]download.php\[/code\]\[code\]^images/([0-9]+)_([a-z0-9_]+).jpg$ /download.php?id=$1\[/code\]
 
Back
Top