diff --git a/Nette/Web/HttpUploadedFile.php b/Nette/Web/HttpUploadedFile.php index 14e3ff2a03..5d0bd6b9aa 100644 --- a/Nette/Web/HttpUploadedFile.php +++ b/Nette/Web/HttpUploadedFile.php @@ -50,9 +50,6 @@ class HttpUploadedFile extends /*Nette\*/Object /* @var string */ private $type; - /* @var string */ - private $realType; - /* @var string */ private $size; @@ -76,7 +73,6 @@ public function __construct($value) //throw new /*\*/InvalidStateException("Filename '$value[tmp_name]' is not a valid uploaded file."); //} $this->name = $value['name']; - $this->type = $value['type']; $this->size = $value['size']; $this->tmpName = $value['tmp_name']; $this->error = $value['error']; @@ -101,19 +97,23 @@ public function getName() */ public function getContentType() { - if ($this->isOk() && $this->realType === NULL) { - if (extension_loaded('fileinfo')) { - $this->realType = finfo_file(finfo_open(FILEINFO_MIME), $this->tmpName); + if ($this->isOk() && $this->type === NULL) { + $info = getimagesize($this->tmpName); + if (isset($info['mime'])) { + $this->type = $info['mime']; - } elseif (function_exists('mime_content_type') && mime_content_type($this->tmpName)) { - $this->realType = mime_content_type($this->tmpName); + } elseif (extension_loaded('fileinfo')) { + $this->type = finfo_file(finfo_open(FILEINFO_MIME), $this->tmpName); - } else { - $info = getImageSize($this->tmpName); - $this->realType = isset($info['mime']) ? $info['mime'] : $this->type; + } elseif (function_exists('mime_content_type')) { + $this->type = mime_content_type($this->tmpName); + } + + if (!$this->type) { + $this->type = 'application/octet-stream'; } } - return $this->realType; + return $this->type; } @@ -140,17 +140,6 @@ public function getTemporaryFile() - /** - * Returns the image. - * @return Nette\Image - */ - public function getImage() - { - return /*Nette\*/Image::fromFile($this->tmpName); - } - - - /** * Returns the path to an uploaded file. * @return string @@ -202,6 +191,28 @@ public function move($dest) + /** + * Is uploaded file GIF, PNG or JPEG? + * @return bool + */ + public function isImage() + { + return in_array($this->getContentType(), array('image/gif', 'image/png', 'image/jpeg'), TRUE); + } + + + + /** + * Returns the image. + * @return Nette\Image + */ + public function getImage() + { + return /*Nette\*/Image::fromFile($this->tmpName); + } + + + /** * Returns the dimensions of an uploaded image as array. * @return array