Commit 322011e9 by Scott

Coding style (qa-blobs.php)

parent deffa191
...@@ -21,74 +21,72 @@ ...@@ -21,74 +21,72 @@
*/ */
// Ensure no PHP errors are shown in the blob response // Ensure no PHP errors are shown in the blob response
@ini_set('display_errors', 0); @ini_set('display_errors', 0);
function qa_blob_db_fail_handler() function qa_blob_db_fail_handler()
{ {
header('HTTP/1.1 500 Internal Server Error'); header('HTTP/1.1 500 Internal Server Error');
qa_exit('error'); qa_exit('error');
} }
// Load the Q2A base file which sets up a bunch of crucial stuff
require 'qa-base.php';
qa_report_process_stage('init_blob'); // Load the Q2A base file which sets up a bunch of crucial stuff
require 'qa-base.php';
// Output the blob in question qa_report_process_stage('init_blob');
require_once QA_INCLUDE_DIR.'app/blobs.php';
qa_db_connect('qa_blob_db_fail_handler'); // Output the blob in question
$blob=qa_read_blob(qa_get('qa_blobid')); require_once QA_INCLUDE_DIR.'app/blobs.php';
if (isset($blob)) { qa_db_connect('qa_blob_db_fail_handler');
$filename=preg_replace('/[^A-Za-z0-9 \\._-]/', '-', $blob['filename']); // for compatibility with HTTP headers and all browsers
header('Cache-Control: max-age=2592000, public'); // allows browsers and proxies to cache the blob
switch ($blob['format']) { $blob = qa_read_blob(qa_get('qa_blobid'));
case 'jpeg':
case 'jpg':
header('Content-Type: image/jpeg');
break;
case 'gif': if (isset($blob)) {
header('Content-Type: image/gif'); // allows browsers and proxies to cache the blob (30 days)
break; header('Cache-Control: max-age=2592000, public');
case 'png': // for compatibility with HTTP headers and all browsers
header('Content-Type: image/png'); $filename = preg_replace('/[^A-Za-z0-9 \\._-]/', '-', $blob['filename']);
break;
case 'pdf': switch ($blob['format']) {
header('Content-Type: application/pdf'); case 'jpeg':
header('Content-Disposition: inline; filename="'.$filename.'"'); case 'jpg':
break; header('Content-Type: image/jpeg');
break;
case 'swf': case 'gif':
header('Content-Type: application/x-shockwave-flash'); header('Content-Type: image/gif');
break; break;
default: case 'png':
header('Content-Type: application/octet-stream'); header('Content-Type: image/png');
header('Content-Disposition: attachment; filename="'.$filename.'"'); break;
break;
}
echo $blob['content']; case 'pdf':
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="'.$filename.'"');
break;
} else case 'swf':
header('HTTP/1.0 404 Not Found'); header('Content-Type: application/x-shockwave-flash');
break;
default:
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.$filename.'"');
break;
}
qa_db_disconnect(); echo $blob['content'];
} else {
header('HTTP/1.0 404 Not Found');
}
/* qa_db_disconnect();
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment