From e2650e93529dae6f532e7bac4013c17a57bb70ad Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sun, 22 Aug 2010 00:05:44 +0200 Subject: save mimetype in DB We don't need the hash in the DB, but for new pastes we use it. Otherwise fallback to old method. Signed-off-by: Florian Pritz --- system/application/models/file_mod.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'system/application') diff --git a/system/application/models/file_mod.php b/system/application/models/file_mod.php index 1eb4efc26..9e9a8b4da 100644 --- a/system/application/models/file_mod.php +++ b/system/application/models/file_mod.php @@ -48,7 +48,7 @@ class File_mod extends Model { function get_filedata($id) { $sql = ' - SELECT hash,filename + SELECT hash,filename,mimetype FROM `files` WHERE `id` = ? LIMIT 1'; @@ -88,10 +88,11 @@ class File_mod extends Model { function add_file($hash, $id, $filename) { + $mimetype = exec(FCPATH.'scripts/mimetype -b --orig-name '.escapeshellarg($filename).' '.escapeshellarg($this->file($hash))); $query = $this->db->query(' - INSERT INTO `files` (`hash`, `id`, `filename`, `password`, `date`) - VALUES (?, ?, ?, ?, ?)', - array($hash, $id, $filename, $this->get_password(), time())); + INSERT INTO `files` (`hash`, `id`, `filename`, `password`, `date`, `mimetype`) + VALUES (?, ?, ?, ?, ?, ?)', + array($hash, $id, $filename, $this->get_password(), time(), $mimetype)); } function show_url($id, $mode) @@ -155,7 +156,7 @@ class File_mod extends Model { } // MODIFIED SINCE SUPPORT -- END - $type = exec(FCPATH.'scripts/mimetype -b --orig-name '.escapeshellarg($filedata['filename']).' '.escapeshellarg($file)); + $type = $filedata['mimetype'] ? $filedata['mimetype'] : exec(FCPATH.'scripts/mimetype -b --orig-name '.escapeshellarg($filedata['filename']).' '.escapeshellarg($file)); if (!$mode && substr_count(ltrim($this->uri->uri_string(), "/"), '/') >= 1) { $mode = $this->mime2extension($type); -- cgit v1.2.3-24-g4f1b