diff options
author | Florian Pritz <bluewind@xinu.at> | 2013-02-03 16:41:17 +0100 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2013-02-03 16:43:03 +0100 |
commit | dda80c29ed4177720c2117c46c1bd134ec61f812 (patch) | |
tree | ed3779471b04073a5d73887fb5f71010ba721bb8 | |
parent | 0fdfe6ad2cf73ddf52dcc67efd9805dede90a2dd (diff) |
Use php's fileinfo instead of perl to detect mimetype
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r-- | INSTALL | 2 | ||||
-rw-r--r-- | application/models/mfile.php | 4 | ||||
-rw-r--r-- | install.php | 1 | ||||
-rwxr-xr-x | scripts/mimetype | 38 |
4 files changed, 4 insertions, 41 deletions
@@ -2,7 +2,7 @@ * run install.php to make sure all dependencies are installed - if you are only creating a basic development installation you will only need: - perl, File::MimeInfo::Magic + perl pygmentize (part of pygments) PHP Memache extension diff --git a/application/models/mfile.php b/application/models/mfile.php index 99e630efe..ec1b8b586 100644 --- a/application/models/mfile.php +++ b/application/models/mfile.php @@ -84,7 +84,9 @@ class Mfile extends CI_Model { { $userid = $this->muser->get_userid(); - $mimetype = exec("perl ".FCPATH.'scripts/mimetype '.escapeshellarg($filename).' '.escapeshellarg($this->file($hash))); + $fileinfo = new finfo(FILEINFO_MIME_TYPE); + $mimetype = $fileinfo->file($this->file($hash)); + $filesize = filesize($this->file($hash)); $query = $this->db->query(' INSERT INTO `files` (`hash`, `id`, `filename`, `user`, `date`, `mimetype`, `filesize`) diff --git a/install.php b/install.php index 48291276a..62aee9341 100644 --- a/install.php +++ b/install.php @@ -32,7 +32,6 @@ $buf == "works" || $errors .= "passthru() failed\n"; // test perl deps $perldeps = array( "HTML::FromANSI", - "File::MimeInfo::Magic", "Text::Markdown" ); foreach ($perldeps as $dep) { diff --git a/scripts/mimetype b/scripts/mimetype deleted file mode 100755 index 330f96ef0..000000000 --- a/scripts/mimetype +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/perl -use warnings; -use strict; -use File::MimeInfo::Magic qw(mimetype globs); - -exit 1 unless @ARGV == 2; - -my $filename = $ARGV[0]; -my $file = $ARGV[1]; -my $type = ""; -my $file_type = ""; - -exit 1 unless -f $file; - -$type = globs($filename); - -# globbing takes priority over all other -if (!$type) { - $type = mimetype($file); - if ($type eq "application/octet-stream") { - # application/octet-stream normally means the detection failed - # use the output of file in this case - $file_type = `file -b --mime-type $file`; - chomp $file_type; - $type = $file_type; - if ($type eq "text/plain") { - # detect ascii with color codes - $file_type = `file -b $file`; - chomp $file_type; - if ($file_type =~ m/ASCII text, (?:with very long lines, )?with escape sequences/) { - $type = "text/plain-ascii"; - } - } - } -} - -print "$type\n"; - |