jon23d Posted September 28, 2009 Share Posted September 28, 2009 I've come to the conclusion that I hate mod_rewrite, so I'd just like to pass everything off to php. I also don't want to have to rely on file extensions for mime type, or deal with the same problems everyone else is having with the php functions to do so. Is there any reason I couldn't just do this? : /** * Serve the provided file to the browser * * Headers cannot have been sent * * Returns FALSE if headers have been sent, * if the file does not exist or is innacessible, * or if it is a folder. * * If $force_save_dialog is true, then the browser * will show a save dialog instead of rendering the contents * * @static * * @param STRING $filename_with_path * @param BOOL $force_save_dialog * @return BOOL */ static function serveFile(STRING $filename_with_path, BOOL $force_save_dialog = false) { // exists? headers sent? if (!is_file($filename_with_path) || headers_sent()) return false; // get mime-type, test for readibility $file_info = apache_lookup_uri($filename_with_path); if (!$file_info->filename) return false; $filename = $file_info->filename; // send the mime-type header('Content-type: ' . $file_info -> content_type); // force save if requested if ($force_save_dialog) header("Content-Disposition: attachment; filename=\"$filename\""); // output file readfile($filename_with_path); return true; } I understand that caching the results of apache_lookup_uri could offer a performance improvement. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.