diff options
-rw-r--r-- | application/config/migration.php | 2 | ||||
-rw-r--r-- | application/controllers/file.php | 33 | ||||
-rw-r--r-- | application/migrations/004_add_filesize.php | 22 | ||||
-rw-r--r-- | application/models/file_mod.php | 7 | ||||
-rw-r--r-- | application/views/file/upload_history.php | 2 | ||||
-rw-r--r-- | application/views/file_plaintext/upload_history.php | 6 |
6 files changed, 65 insertions, 7 deletions
diff --git a/application/config/migration.php b/application/config/migration.php index 3e824520a..0bd1d7c44 100644 --- a/application/config/migration.php +++ b/application/config/migration.php @@ -21,7 +21,7 @@ $config['migration_enabled'] = true; | be upgraded / downgraded to. | */ -$config['migration_version'] = 3; +$config['migration_version'] = 4; /* diff --git a/application/controllers/file.php b/application/controllers/file.php index e5e984b21..b8b22f12b 100644 --- a/application/controllers/file.php +++ b/application/controllers/file.php @@ -127,7 +127,7 @@ class File extends CI_Controller { if (! $cached = $this->memcachelibrary->get("history_".$this->var->view_dir."_".$user)) { $query = array(); $lengths = array(); - $fields = array("id", "filename", "mimetype", "date", "hash"); + $fields = array("id", "filename", "mimetype", "date", "hash", "filesize"); $this->data['title'] .= ' - Upload history'; foreach($fields as $length_key) { $lengths[$length_key] = 0; @@ -142,6 +142,7 @@ class File extends CI_Controller { foreach($query as $key => $item) { $query[$key]["date"] = date("r", $item["date"]); + $query[$key]["filesize"] = format_bytes($item["filesize"]); if ($this->var->cli_client) { // Keep track of longest string to pad plaintext output correctly foreach($fields as $length_key) { @@ -343,6 +344,36 @@ class File extends CI_Controller { } closedir($outer_dh); } + + function update_file_sizes() + { + if (!$this->input->is_cli_request()) return; + + $chunk = 500; + + $total = $this->db->count_all("files"); + + for ($limit = 0; $limit < $total; $limit += $chunk) { + $query = $this->db->query(" + SELECT hash + FROM files + GROUP BY hash + LIMIT $limit, $chunk + ")->result_array(); + + foreach ($query as $key => $item) { + $hash = $item["hash"]; + $filesize = intval(filesize($this->file_mod->file($hash))); + $this->db->query(" + UPDATE files + SET filesize = ? + WHERE hash = ? + ", array($filesize, $hash)); + } + } + + + } } # vim: set noet: diff --git a/application/migrations/004_add_filesize.php b/application/migrations/004_add_filesize.php new file mode 100644 index 000000000..d7a70223d --- /dev/null +++ b/application/migrations/004_add_filesize.php @@ -0,0 +1,22 @@ +<?php +defined('BASEPATH') OR exit('No direct script access allowed'); + +class Migration_Add_filesize extends CI_Migration { + + public function up() + { + $this->db->query(" + ALTER TABLE `files` + ADD `filesize` INT UNSIGNED NOT NULL + "); + } + + public function down() + { + $this->db->query(" + ALTER TABLE `files` + DROP `filesize` + "); + + } +} diff --git a/application/models/file_mod.php b/application/models/file_mod.php index b6194a39e..ffd031ace 100644 --- a/application/models/file_mod.php +++ b/application/models/file_mod.php @@ -88,10 +88,11 @@ class File_mod extends CI_Model { $userid = $this->muser->get_userid(); $mimetype = exec("perl ".FCPATH.'scripts/mimetype '.escapeshellarg($filename).' '.escapeshellarg($this->file($hash))); + $filesize = filesize($this->file($hash)); $query = $this->db->query(' - INSERT INTO `files` (`hash`, `id`, `filename`, `user`, `date`, `mimetype`) - VALUES (?, ?, ?, ?, ?, ?)', - array($hash, $id, $filename, $userid, time(), $mimetype)); + INSERT INTO `files` (`hash`, `id`, `filename`, `user`, `date`, `mimetype`, `filesize`) + VALUES (?, ?, ?, ?, ?, ?, ?)', + array($hash, $id, $filename, $userid, time(), $mimetype, $filesize)); } function show_url($id, $mode) diff --git a/application/views/file/upload_history.php b/application/views/file/upload_history.php index 1dcaa8053..8f0f8e3d7 100644 --- a/application/views/file/upload_history.php +++ b/application/views/file/upload_history.php @@ -6,6 +6,7 @@ <th>Mimetype <th>Date</th> <th>Hash</th> + <th>Size</th> </tr> <?php foreach($query as $key => $item): ?> @@ -16,6 +17,7 @@ <td><?php echo $item["mimetype"]; ?></td> <td><?php echo $item["date"]; ?></td> <td><?php echo $item["hash"]; ?></td> + <td><?php echo $item["filesize"]; ?></td> </tr> <?php endforeach; ?> </table> diff --git a/application/views/file_plaintext/upload_history.php b/application/views/file_plaintext/upload_history.php index e03311464..4e9308d91 100644 --- a/application/views/file_plaintext/upload_history.php +++ b/application/views/file_plaintext/upload_history.php @@ -4,7 +4,8 @@ echo .mb_str_pad("Filename", $lengths["filename"])." | " .mb_str_pad("Mimetype", $lengths["mimetype"])." | " .mb_str_pad("Date", $lengths["date"])." | " - .mb_str_pad("Hash", $lengths["hash"])."\n"; + .mb_str_pad("Hash", $lengths["hash"])." | " + .mb_str_pad("Size", $lengths["filesize"])."\n"; foreach($query as $key => $item) { echo @@ -12,6 +13,7 @@ foreach($query as $key => $item) { .mb_str_pad($item["filename"], $lengths["filename"])." | " .mb_str_pad($item["mimetype"], $lengths["mimetype"])." | " .$item["date"]." | " - .$item["hash"]."\n"; + .$item["hash"]." | " + .$item["filesize"]."\n"; } |