0) && file_exists($log_path)) { $linecount = count(file($log_path)); if($linecount > ($maxlines - 1)) { delete_lines($log_path,$linecount - ($maxlines - 1)); //delete top lines as needed } } //write out the output if(!($fp = fopen($log_path,'a+'))) { //if for some reason this fails just return, user will get no image return; } fwrite($fp,$output); fclose($fp); //if you add more types in .htaccess remember to put them here as well! switch($extension) { case 'bmp': header("Content-Type: image/bmp\n"); break; case 'ico': header("Content-Type: image/vnd.microsoft.icon\n"); break; case 'jpg': case 'jpeg': header("Content-Type: image/jpeg\n"); break; case 'png': header("Content-Type: image/png\n"); break; case 'gif': header("Content-Type: image/gif\n"); break; default: return; //don't return nuttin for unknown types. } //set encoding to binary header("Content-Transfer-Encoding: binary"); $doc_root = rtrim($_SERVER['DOCUMENT_ROOT'],'/'); //to prevent double slash further down $request = ltrim($request,'/'); if(!file_exists($doc_root . "/$request")) { header("HTTP/1.0 404 Not Found"); return; } //return the image to the calling url. You could also get fancy and print out another image like the goatse :P if($fp=fopen($doc_root . "/$request", "r")) { if($fp) { fpassthru($fp); } fclose($fp); } //functions function delete_lines($file,$num) { //I'm sure this could be greatly optimized! if(($arr = file($file)) === false) { return; } $arr2 = array_slice($arr,$num); if(($fp = fopen($file,'w')) === false) { return; } foreach($arr2 as $line) { fputs($fp,$line); } fclose($fp); } ?>