/** * Validate some possible input for the field. * * @param mixed Input * @return string Path to the file relative to 'upload_path' */ function clean($value) { parent::clean($value); if (is_null($value) and !$this->required) { return ''; // no file } elseif (is_null($value) and $this->required) { throw new Pluf_Form_Invalid(__('No files were uploaded. Please try to send the file again.')); } $errors = array(); $no_files = false; switch ($value['error']) { case UPLOAD_ERR_OK: break; case UPLOAD_ERR_INI_SIZE: throw new Pluf_Form_Invalid(sprintf(__('The uploaded file is too large. Reduce the size of the file to %s and send it again.'), Pluf_Utils::prettySize(ini_get('upload_max_filesize')))); break; case UPLOAD_ERR_FORM_SIZE: throw new Pluf_Form_Invalid(sprintf(__('The uploaded file is too large. Reduce the size of the file to %s and send it again.'), Pluf_Utils::prettySize($_REQUEST['MAX_FILE_SIZE']))); break; case UPLOAD_ERR_PARTIAL: throw new Pluf_Form_Invalid(__('The upload did not complete. Please try to send the file again.')); break; case UPLOAD_ERR_NO_FILE: if ($this->required) { throw new Pluf_Form_Invalid(__('No files were uploaded. Please try to send the file again.')); } else { return ''; // no file } break; case UPLOAD_ERR_NO_TMP_DIR: case UPLOAD_ERR_CANT_WRITE: throw new Pluf_Form_Invalid(__('The server has no temporary folder correctly configured to store the uploaded file.')); break; case UPLOAD_ERR_EXTENSION: throw new Pluf_Form_Invalid(__('The uploaded file has been stopped by an extension.')); break; default: throw new Pluf_Form_Invalid(__('An error occured when upload the file. Please try to send the file again.')); } if ($value['size'] > $this->max_size) { throw new Pluf_Form_Invalid(sprintf(__('The uploaded file is to big (%1$s). Reduce the size to less than %2$s and try again.'), Pluf_Utils::prettySize($value['size']), Pluf_Utils::prettySize($this->max_size))); } // copy the file to the final destination and updated $value // with the final path name. 'final_name' is relative to // Pluf::f('upload_path') Pluf::loadFunction($this->move_function); // Should throw a Pluf_Form_Invalid exception if error or the // value to be stored in the database. return call_user_func($this->move_function, $value, $this->move_function_params); }
/** * Display the size of the project. * * @param string Field * @param IDF_Project * @return string */ function IDF_Views_Admin_projectSize($field, $project) { $size = $project->getRepositorySize(); if ($size == -1) { return ''; } return Pluf_Utils::prettySize($size); }
function IDF_Views_Source_PrettySizeSimple($size) { return Pluf_Utils::prettySize($size); }
function IDF_Views_Download_Size($field, $down) { return Pluf_Utils::prettySize($down->{$field}); }