diff options
| author | Christian Weiske <cweiske@cweiske.de> | 2012-06-05 16:11:52 +0200 |
|---|---|---|
| committer | Christian Weiske <cweiske@cweiske.de> | 2012-06-05 16:11:52 +0200 |
| commit | 3543bfd4d6c2ff90417d775b4eac74e1f2bd8d10 (patch) | |
| tree | 15d60efeb5b45f4a9c68502a7e9d1a069d7ffbc6 /src/phorkie/Repository/Post.php | |
| parent | e5dd490175334f5a9a2dc93d8b500df480bb4f60 (diff) | |
| download | phorkie-3543bfd4d6c2ff90417d775b4eac74e1f2bd8d10.tar.gz phorkie-3543bfd4d6c2ff90417d775b4eac74e1f2bd8d10.zip | |
automatic detection of file types
Diffstat (limited to 'src/phorkie/Repository/Post.php')
| -rw-r--r-- | src/phorkie/Repository/Post.php | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/phorkie/Repository/Post.php b/src/phorkie/Repository/Post.php index 438bf5a..d104a8c 100644 --- a/src/phorkie/Repository/Post.php +++ b/src/phorkie/Repository/Post.php @@ -48,6 +48,11 @@ class Repository_Post $orignalName = Tools::sanitizeFilename($arFile['original_name']); $name = Tools::sanitizeFilename($arFile['name']); + if ($arFile['type'] == '_auto_') { + //FIXME: upload + $arFile['type'] = $this->getType($arFile['content']); + } + if ($name == '') { if ($bUpload) { $name = Tools::sanitizeFilename($_FILES['files']['name'][$num]['upload']); @@ -163,6 +168,28 @@ class Repository_Post return $prefix . $num; } + + protected function getType($content) + { + $tmp = tempnam(sys_get_temp_dir(), 'phorkie-autodetect-'); + file_put_contents($tmp, $content); + $type = \MIME_Type_PlainDetect::autoDetect($tmp); + unlink($tmp); + + return $this->findExtForType($type); + } + + protected function findExtForType($type) + { + $ext = 'text/plain'; + foreach ($GLOBALS['phorkie']['languages'] as $lext => $arLang) { + if ($arLang['mime'] == $type) { + $ext = $lext; + break; + } + } + return $ext; + } } ?> |
