mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-26 13:09:15 +00:00
136 lines
2.1 KiB
PHP
136 lines
2.1 KiB
PHP
<?php
|
|
namespace Pecee\Http\Input;
|
|
|
|
class InputFile extends InputItem
|
|
{
|
|
public $size;
|
|
public $type;
|
|
public $error;
|
|
public $tmpName;
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getSize()
|
|
{
|
|
return $this->size;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getType()
|
|
{
|
|
return $this->type;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getError()
|
|
{
|
|
return $this->error;
|
|
}
|
|
|
|
public function getMime()
|
|
{
|
|
return $this->getType();
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getTmpName()
|
|
{
|
|
return $this->tmpName;
|
|
}
|
|
|
|
public function getExtension()
|
|
{
|
|
return pathinfo($this->getName(), PATHINFO_EXTENSION);
|
|
}
|
|
|
|
public function move($destination)
|
|
{
|
|
return move_uploaded_file($this->tmpName, $destination);
|
|
}
|
|
|
|
public function getContents()
|
|
{
|
|
return file_get_contents($this->tmpName);
|
|
}
|
|
|
|
/**
|
|
* Set file temp. name
|
|
* @param string $name
|
|
* @return static $this
|
|
*/
|
|
public function setTmpName($name)
|
|
{
|
|
$this->tmpName = $name;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set file size
|
|
* @param int $size
|
|
* @return static $this
|
|
*/
|
|
public function setSize($size)
|
|
{
|
|
$this->size = $size;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set type
|
|
* @param string $type
|
|
* @return static $this
|
|
*/
|
|
public function setType($type)
|
|
{
|
|
$this->type = $type;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set error
|
|
* @param int $error
|
|
* @return static $this
|
|
*/
|
|
public function setError($error)
|
|
{
|
|
$this->error = $error;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Create from array
|
|
* @param array $values
|
|
* @return static
|
|
*/
|
|
public static function createFromArray(array $values)
|
|
{
|
|
if(!isset($values['index'])) {
|
|
throw new \InvalidArgumentException('Index key is required');
|
|
}
|
|
|
|
$input = new static($values['index']);
|
|
$input->setTmpName((isset($values['error']) ? $values['error'] : null));
|
|
$input->setName((isset($values['name']) ? $values['name'] : null));
|
|
$input->setSize((isset($values['size']) ? $values['size'] : null));
|
|
$input->setType((isset($values['type']) ? $values['type'] : null));
|
|
$input->setError((isset($values['tmp_name']) ? $values['tmp_name'] : null));
|
|
|
|
return $input;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getValue()
|
|
{
|
|
return $this->tmpName;
|
|
}
|
|
|
|
} |