34 private $test =
false;
41 private $originalName;
88 public function __construct($path, $originalName, $mimeType =
null, $size =
null, $error =
null, $test =
false)
90 $this->originalName = $this->
getName($originalName);
91 $this->mimeType = $mimeType ?:
'application/octet-stream';
93 $this->error = $error ?: UPLOAD_ERR_OK;
94 $this->test = (bool) $test;
96 parent::__construct($path, UPLOAD_ERR_OK === $this->error);
109 return $this->originalName;
122 return pathinfo($this->originalName, PATHINFO_EXTENSION);
140 return $this->mimeType;
165 return $guesser->guess($type);
201 $isOk = $this->error === UPLOAD_ERR_OK;
203 return $this->test ? $isOk : $isOk && is_uploaded_file($this->getPathname());
216 public function move($directory, $name =
null)
220 return parent::move($directory, $name);
225 if (!@move_uploaded_file($this->getPathname(), $target)) {
226 $error = error_get_last();
227 throw new FileException(sprintf(
'Could not move the file "%s" to "%s" (%s)', $this->getPathname(), $target, strip_tags($error[
'message'])));
230 @chmod($target, 0666 & ~umask());
245 $iniMax = strtolower(ini_get(
'upload_max_filesize'));
247 if (
'' === $iniMax) {
251 $max = ltrim($iniMax,
'+');
252 if (0 === strpos($max,
'0x')) {
253 $max = intval($max, 16);
254 } elseif (0 === strpos($max,
'0')) {
255 $max = intval($max, 8);
260 switch (substr($iniMax, -1)) {
261 case 't': $max *= 1024;
262 case 'g': $max *= 1024;
263 case 'm': $max *= 1024;
264 case 'k': $max *= 1024;
277 static $errors = array(
278 UPLOAD_ERR_INI_SIZE =>
'The file "%s" exceeds your upload_max_filesize ini directive (limit is %d KiB).',
279 UPLOAD_ERR_FORM_SIZE =>
'The file "%s" exceeds the upload limit defined in your form.',
280 UPLOAD_ERR_PARTIAL =>
'The file "%s" was only partially uploaded.',
281 UPLOAD_ERR_NO_FILE =>
'No file was uploaded.',
282 UPLOAD_ERR_CANT_WRITE =>
'The file "%s" could not be written on disk.',
283 UPLOAD_ERR_NO_TMP_DIR =>
'File could not be uploaded: missing temporary directory.',
284 UPLOAD_ERR_EXTENSION =>
'File upload was stopped by a PHP extension.',
287 $errorCode = $this->error;
289 $message = isset($errors[$errorCode]) ? $errors[$errorCode] :
'The file "%s" was not uploaded due to an unknown error.';