X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fplupload.php;h=67b41dcd109e031f1cc8e6a9e5b8766565546148;hb=a7f778a593a0a7e168a7112ec28cb84d032adaf3;hp=133b55da661ce249854007d5970db37a9aff3aba;hpb=756ff73fbb0cdd01cce2eda27ba18e1cc99bd735;p=platal.git diff --git a/classes/plupload.php b/classes/plupload.php index 133b55d..67b41dc 100644 --- a/classes/plupload.php +++ b/classes/plupload.php @@ -1,6 +1,6 @@ file_id = $filename; $this->category = $category; - $this->forlife = $forlife; + $this->hruid = $hruid; $this->filename = $this->makeFilename($this->file_id); $this->checkContentType(); } @@ -49,13 +49,13 @@ class PlUpload private function makeFilename($file_id) { global $globals; - $filename = $globals->spoolroot . '/spool/uploads/temp/'; + $filename = $globals->spoolroot . '/spool/tmp/'; if (!file_exists($filename)) { if (!mkdir($filename)) { trigger_error('can\'t create upload directory: ' . $filename, E_USER_ERROR); } } - $filename .= $this->forlife . '--' . $this->category; + $filename .= $this->hruid . '--' . $this->category; if ($file_id) { $filename .= '--' . $file_id; } @@ -66,6 +66,9 @@ class PlUpload { if ($this->exists()) { $this->type = trim(mime_content_type($this->filename)); + if ($this->type == 'text/plain') { // Workaround a bug of php 5.2.0+etch10 (mime_content_type fallback is 'text/plain') + $this->type = preg_replace('/;.*/', '', trim(shell_exec('file -bi ' . escapeshellarg($this->filename)))); + } } } @@ -121,9 +124,9 @@ class PlUpload return true; } - static public function &get(array &$file, $forlife, $category, $uniq = false) + static public function &get(array &$file, $hruid, $category, $uniq = false) { - $upload = new PlUpload($forlife, $category, $uniq ? null : $file['name']); + $upload = new PlUpload($hruid, $category, $uniq ? null : $file['name']); if (!$upload->upload($file)) { $upload = null; } @@ -156,11 +159,11 @@ class PlUpload return file_exists($this->filename); } - static public function listRawFiles($forlife = '*', $category = '*', $uniq = false, $basename = false) + static public function listRawFiles($hruid = '*', $category = '*', $uniq = false, $basename = false) { global $globals; - $filename = $globals->spoolroot . '/spool/uploads/temp/'; - $filename .= $forlife . '--' . $category; + $filename = $globals->spoolroot . '/spool/tmp/'; + $filename .= $hruid . '--' . $category; if (!$uniq) { $filename .= '--*'; } @@ -171,23 +174,23 @@ class PlUpload return $files; } - static public function listFilenames($forlife = '*', $category = '*') + static public function listFilenames($hruid = '*', $category = '*') { - $files = PlUpload::listRawFiles($forlife, $category, false, true); + $files = PlUpload::listRawFiles($hruid, $category, false, true); foreach ($files as &$name) { - list($forlife, $cat, $fn) = explode('--', $name, 3); + list($hruid, $cat, $fn) = explode('--', $name, 3); $name = $fn; } return $files; } - static public function &listFiles($forlife = '*', $category = '*', $uniq = false) + static public function &listFiles($hruid = '*', $category = '*', $uniq = false) { $res = array(); - $files = PlUpload::listRawFiles($forlife, $category, $uniq, true); + $files = PlUpload::listRawFiles($hruid, $category, $uniq, true); foreach ($files as $name) { - list($forlife, $cat, $fn) = explode('--', $name, 3); - $res[$fn] = new PlUpload($forlife, $cat, $fn); + list($hruid, $cat, $fn) = explode('--', $name, 3); + $res[$fn] = new PlUpload($hruid, $cat, $fn); } return $res; } @@ -228,6 +231,10 @@ class PlUpload $array = getimagesize($this->filename); $array[2] = @$map[$array[2]]; if (!$array[2]) { + list($image, $type) = explode('/', $array['mime']); + $array[2] = $type; + } + if (!$array[2]) { trigger_error('unknown image type', E_USER_NOTICE); return null; }