summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xssn.at>2010-08-22 00:05:44 +0200
committerFlorian Pritz <bluewind@xssn.at>2010-08-22 00:05:44 +0200
commite2650e93529dae6f532e7bac4013c17a57bb70ad (patch)
tree33c65bb638e1f29340c08e99fc1a8021ff404eb7
parent02bee5d0f91dd472d1969776304ceeb0f7dada93 (diff)
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 <bluewind@xssn.at>
-rw-r--r--system/application/models/file_mod.php11
1 files changed, 6 insertions, 5 deletions
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);