function test_file_mime_content_type() { assert_not_empty(file_mime_content_type('')); assert_not_empty(file_mime_content_type('my_file')); assert_equal(file_mime_content_type('my_file'), 'application/octet-stream'); assert_equal(file_mime_content_type('my_file.txt'), 'text/plain'); assert_equal(file_mime_content_type('my_file.TXT'), 'text/plain'); assert_equal(file_mime_content_type('my_file.jpg'), 'image/jpeg'); assert_equal(file_mime_content_type('my_file.JPG'), 'image/jpeg'); }
/** * Checks if $filename is a text file * * @param string $filename * @return bool */ function file_is_text($filename) { if ($mime = file_mime_content_type($filename)) { return substr($mime, 0, 5) == "text/"; } return null; }
/** * Send a file through the standart output * @param App_Model_File $file File to send */ protected function sendFile(App_Model_File $file) { $mime = file_mime_content_type($file->getFileName()); header('Content-Type: ' . $mime); header('Content-Disposition: attachment; filename="' . iconv("UTF-8", "ISO-8859-1", $file->getFileName()) . '"'); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . $file->file_size); return file_read($file->getOnDiskLocation()); }