File io/http/upload/FileUploadService.class.php
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49:
<?php
/**
* Manages the HTTP file upload
* @package IO
* @subpackage HTTP\upload
* @copyright © 2005-2019 PHPBoost
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU/GPL-3.0
* @author Benoit SAUTEL <ben.popeye@phpboost.com>
* @version PHPBoost 5.2 - last update: 2014 12 22
* @since PHPBoost 3.0 - 2010 01 24
*/
class FileUploadService
{
/**
*
* @param string $varname
* @return UploadedFile
* @throws UploadedFileTooLargeException if the file is too big
* @throws Exception if an unknown error occurs
*/
public static function retrieve_file($varname)
{
$properties = $_FILES[$varname];
switch($properties['error'])
{
case UPLOAD_ERR_OK:
return self::build_file($properties);
case UPLOAD_ERR_INI_SIZE:
case UPLOAD_ERR_FORM_SIZE:
throw new UploadedFileTooLargeException($varname, $properties['name']);
break;
default:
throw new Exception('The file of the field <i>' . $varname . '</i> of the HTTP request couldn\'t be uploaded');
break;
}
}
/**
* @return UploadedFile
*/
private static function build_file(array $properties)
{
return $file = new UploadedFile($properties['name'], $properties['type'], $properties['size'], $properties['tmp_name']);
}
}
?>