/** * Handle upload. */ protected function handle_upload() { $upload = $this->request->file($this->form_name); if ($upload['name'] != 'none' && trim($upload['name'])) { // Try uploading the file. $this->upload_file(); // Store for easier access $this->errors = array_merge($this->errors, $this->filedata['error']); // If we had no problems we can submit the data to the database. if (empty($this->filedata['error'])) { $order_id = $this->set_custom_order ? $this->operator->get_max_custom_index() + 1 : 0; $data = array('attachment_id' => 0, 'physical_filename' => $this->filedata['physical_filename'], 'attachment_directory' => $this->filedata['attachment_directory'], 'real_filename' => $this->filedata['real_filename'], 'extension' => $this->filedata['extension'], 'mimetype' => $this->filedata['mimetype'], 'filesize' => $this->filedata['filesize'], 'filetime' => $this->filedata['filetime'], 'hash' => $this->filedata['md5_checksum'], 'attachment_order' => $order_id, 'attachment_comment' => $this->request->variable('filecomment', '', true), 'object_type' => $this->object_type, 'object_id' => $this->object_id); $attachment = $this->operator->get_new_entity($data); // Create thumbnail $has_thumbnail = $is_preview = false; if ($this->filedata['is_image']) { $has_thumbnail = $attachment->create_thumbnail($this->max_thumbnail_width, $this->max_thumbnail_width === false ? false : 0); // set first screenshot as preview image when it is uploaded $is_preview = !$this->operator->get_count(); } $attachment->__set_array(array('thumbnail' => $has_thumbnail, 'is_preview' => $is_preview)); $attachment->submit(); // Store in operator $this->operator->set($attachment); $this->uploaded = $attachment->get_id(); } } // We do not want to upload it again if this function is called again. $this->request->overwrite($this->form_name, null, request_interface::FILES); }