/** * @param FOLDER $folder */ public function __construct($folder) { parent::__construct($folder->app); $this->_folder = $folder; $field = new UPLOAD_FILE_FIELD(); $field->id = 'zipfile'; $field->caption = 'Zip file'; $field->description = 'Please specify a zip file containing your pictures.'; $field->required = true; $field->max_bytes = text_to_file_size('30MB'); $this->add_field($field); $field = new MUNGER_TITLE_FIELD(); $field->id = 'title'; $field->caption = 'Title'; $field->description = 'Each picture entry will have this title. Use {#} to include the picture number and {file} to include the file name without the extension. For example, if the title is \'Picture {#} - {file}\', file1.jpg will have the title \'Picture 1 - file1\').'; $field->required = true; $this->add_field($field); $field = new BOOLEAN_FIELD(); $field->id = 'read_exif'; $field->caption = 'Read EXIF info'; $this->add_field($field); $field = new DATE_TIME_FIELD(); $field->id = 'day'; $field->caption = 'Day'; $field->required = true; $this->add_field($field); $field = new BOOLEAN_FIELD(); $field->id = 'create_thumbnail'; $field->caption = 'Create thumbnails'; $this->add_field($field); $field = new INTEGER_FIELD(); $field->id = 'thumbnail_size'; $field->caption = 'Thumbnail size'; $field->min_value = 32; $field->max_value = 300; $this->add_field($field); $field = new INTEGER_FIELD(); $field->id = 'starting_index'; $field->caption = 'First number'; $field->required = true; $field->description = 'Set the next number to use for {#} in the title (if uploading in multiple batches).'; $field->min_value = 1; $this->add_field($field); }
/** * @param ALBUM $folder Album in which to add or edit the picture. */ public function __construct($folder) { parent::__construct($folder); $field = new TEXT_FIELD(); $field->id = 'file_name'; $field->caption = 'File Name'; $field->min_length = 1; $field->max_length = 1000; $this->add_field($field); $field = new UPLOAD_FILE_FIELD(); $field->id = 'upload_file'; $field->caption = 'Picture'; $field->max_bytes = text_to_file_size('2MB'); $this->add_field($field); $field = new BOOLEAN_FIELD(); $field->id = 'create_thumbnail'; $field->caption = 'Create a thumbnail'; $field->sticky = true; $this->add_field($field); $field = new INTEGER_FIELD(); $field->id = 'thumbnail_size'; $field->caption = 'Thumbnail size'; $field->min_value = 32; $field->max_value = 400; $field->sticky = true; $this->add_field($field); $field = new BOOLEAN_FIELD(); $field->id = 'overwrite'; $field->caption = 'Overwrite existing file'; $field->sticky = true; $this->add_field($field); $field = new BOOLEAN_FIELD(); $field->id = 'read_exif'; $field->caption = 'Read EXIF info'; $field->sticky = true; $this->add_field($field); $field = new BOOLEAN_FIELD(); $field->id = 'use_upload'; $field->sticky = true; $this->add_field($field); $field = $this->field_at('day'); $field->required = false; }
public function load_from_request() { $this->upload_max_filesize = text_to_file_size(ini_get('upload_max_filesize')); $this->post_max_size = text_to_file_size(ini_get('post_max_size')); $this->ini_max_file_size = min($this->upload_max_filesize, $this->post_max_size); $this->max_file_size = $this->ini_max_file_size; $this->form_max_file_size = read_var(Form_max_file_size_field_name, 0); if ($this->form_max_file_size && $this->form_max_file_size < $this->max_file_size) { $this->max_file_size = $this->form_max_file_size; } $this->_file_sets = array(); $this->total_files = 0; foreach ($_FILES as $file_set_id => $file_info) { $file_set = new UPLOADED_FILE_SET($this, $file_set_id); if ($file_set->size()) { $this->total_files += $file_set->size(); $this->file_sets[$file_set_id] = $file_set; } } /* In order to smoothly support uploading with form validation, we allow a form to process a previously uploaded file and store its properties in the form. The uploader reads those values and 'pretends' that this is a valid PHP upload file. This way, form validation can occur over multiple submissions but a successfully uploaded file need only be uploaded once. */ $uploads = read_var($this->stored_info_name); if (is_array($uploads)) { for ($idx = sizeof($uploads) - 1; $idx >= 0; $idx--) { $upload = $uploads[$idx]; $file = new UPLOADED_FILE($this, '', 0, '', '', 0); $file_set_id = $file->load_from_text($upload); if (isset($this->file_sets[$file_set_id])) { $file_set = $this->file_sets[$file_set_id]; } else { $file_set = new UPLOADED_FILE_SET($this, $file_set_id); $this->file_sets[$file_set_id] = $file_set; } array_unshift($file_set->files, $file); } } }
private function _test_file_sizes() { $this->_check_equal(4096, text_to_file_size('4KB')); $this->_check_equal(4096, text_to_file_size('4K')); $this->_check_equal(4096 * 1024, text_to_file_size('4MB')); $this->_check_equal(4096 * 1024, text_to_file_size('4M')); $this->_check_equal(4096 * 1024 * 1024, text_to_file_size('4GB')); $this->_check_equal(4096 * 1024 * 1024, text_to_file_size('4G')); $this->_check_equal(4096 * 1024 * 1024 * 1024, text_to_file_size('4TB')); $this->_check_equal(4096 * 1024 * 1024 * 1024, text_to_file_size('4T')); }