summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--application/controllers/file.php14
-rw-r--r--application/models/mfile.php11
2 files changed, 16 insertions, 9 deletions
diff --git a/application/controllers/file.php b/application/controllers/file.php
index 429efbe6e..333602fbf 100644
--- a/application/controllers/file.php
+++ b/application/controllers/file.php
@@ -57,8 +57,8 @@ class File extends CI_Controller {
echo " nuke_id <ID> Nukes all IDs sharing the same hash\n";
echo "\n";
echo "Functions that shouldn't have to be run:\n";
- echo " clean_stale_files Remove files without database entries\n";
- echo " update_file_sizes Update filesize in database\n";
+ echo " clean_stale_files Remove files without database entries\n";
+ echo " update_file_metadata Update filesize and mimetype in database\n";
exit;
}
// Try to guess what the user would like to do.
@@ -736,7 +736,7 @@ class File extends CI_Controller {
echo "removed hash \"$hash\"\n";
}
- function update_file_sizes()
+ function update_file_metadata()
{
if (!$this->input->is_cli_request()) return;
@@ -755,15 +755,15 @@ class File extends CI_Controller {
foreach ($query as $key => $item) {
$hash = $item["hash"];
$filesize = intval(filesize($this->mfile->file($hash)));
+ $mimetype = $this->mfile->mimetype($this->mfile->file($hash));
+
$this->db->query("
UPDATE files
- SET filesize = ?
+ SET filesize = ?, mimetype = ?
WHERE hash = ?
- ", array($filesize, $hash));
+ ", array($filesize, $mimetype, $hash));
}
}
-
-
}
}
diff --git a/application/models/mfile.php b/application/models/mfile.php
index ef48a87c5..203e2e101 100644
--- a/application/models/mfile.php
+++ b/application/models/mfile.php
@@ -79,13 +79,20 @@ class Mfile extends CI_Model {
return $this->folder($hash).'/'.$hash;
}
+ // Return mimetype of file
+ function mimetype($file) {
+ $fileinfo = new finfo(FILEINFO_MIME_TYPE);
+ $mimetype = $fileinfo->file($file);
+
+ return $mimetype;
+ }
+
// Add a hash to the DB
function add_file($hash, $id, $filename)
{
$userid = $this->muser->get_userid();
- $fileinfo = new finfo(FILEINFO_MIME_TYPE);
- $mimetype = $fileinfo->file($this->file($hash));
+ $mimetype = $this->mimetype($this->file($hash));
$filesize = filesize($this->file($hash));
$query = $this->db->query('