90 $this->_allowScripts = $value;
100 $this->_minSize = trim($size);
110 $this->_maxSize = trim($size);
120 if (!is_array($value))
121 $value = explode(
'|', $value);
122 $this->_types = $value;
132 if (!is_array($value))
133 $value = explode(
'|', $value);
134 $this->_extensions = $value;
174 public function save($name = NULL)
203 if ($this->
save($name)) {
218 if ($_FILES[$this->_name][
'error'] > 0) {
220 UPLOAD_ERR_INI_SIZE =>
'el archivo excede el tamaño máximo (' . ini_get(
'upload_max_filesize') .
'b) permitido por el servidor',
221 UPLOAD_ERR_FORM_SIZE =>
'el archivo excede el tamaño máximo permitido',
222 UPLOAD_ERR_PARTIAL =>
'se ha subido el archivo parcialmente',
223 UPLOAD_ERR_NO_FILE =>
'no se ha subido ningún archivo',
224 UPLOAD_ERR_NO_TMP_DIR =>
'no se encuentra el directorio de archivos temporales',
225 UPLOAD_ERR_CANT_WRITE =>
'falló al escribir el archivo en disco',
226 UPLOAD_ERR_EXTENSION =>
'una extensión de php ha detenido la subida del archivo'
229 Flash::error(
'Error: ' . $error[$_FILES[$this->_name][
'error']]);
243 if (!$this->_allowScripts && preg_match(
'/\.(php|phtml|php3|php4|js|shtml|pl|py|rb|rhtml)$/i', $_FILES[$this->_name][
'name'])) {
244 Flash::error(
'Error: no esta permitido subir scripts ejecutables');
255 if ($this->_extensions !== NULL && !preg_match(
'/\.(' . implode(
'|', $this->_extensions) .
')$/i', $_FILES[$this->_name][
'name'])) {
256 Flash::error(
'Error: la extensión del archivo no es válida');
261 if ($this->_maxSize !== NULL && $_FILES[$this->_name][
'size'] > $this->
_toBytes($this->_maxSize)) {
262 Flash::error(
"Error: no se admiten archivos superiores a $this->_maxSize" .
'b');
267 if ($this->_minSize !== NULL && $_FILES[$this->_name][
'size'] < $this->
_toBytes($this->_minSize)) {
268 Flash::error(
"Error: no se admiten archivos inferiores a $this->_minSize" .
'b');
282 return in_array($_FILES[$this->_name][
'type'], $this->_types);
292 if($ext = pathinfo($_FILES[$this->_name][
'name'], PATHINFO_EXTENSION)){
308 if (file_exists(
"$this->_path/$name")) {
309 Flash::error(
'Error: ya existe este fichero. Y no se permite reescribirlo');
323 if (is_int($size) || ctype_digit($size)) {
327 $tipo = strtolower(substr($size, -1));
342 Flash::error(
'Error: el tamaño debe ser un int para bytes, o un string terminado con K, M o G. Ej: 30k , 2M, 2G');
354 protected abstract function _saveFile($name);
363 public static function factory($name, $adapter =
'file')
365 require_once dirname(__FILE__) .
"/adapters/{$adapter}_upload.php";
366 $class = $adapter .
'upload';
368 return new $class($name);