Skip to content

Commit

Permalink
- HttpUploadedFile: no longer takes into account the sent mime-type
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Aug 3, 2009
1 parent a05370a commit ae42f74
Showing 1 changed file with 35 additions and 24 deletions.
59 changes: 35 additions & 24 deletions Nette/Web/HttpUploadedFile.php
Expand Up @@ -50,9 +50,6 @@ class HttpUploadedFile extends /*Nette\*/Object
/* @var string */
private $type;

/* @var string */
private $realType;

/* @var string */
private $size;

Expand All @@ -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'];
Expand All @@ -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;
}


Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ae42f74

Please sign in to comment.