Example #1
0
 /**
  * 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);
 }
Example #2
0
 /**
  * Checks whether the chunk we are about to deal with was actually uploaded
  * by PHP and actually exists, if not, it generates an error
  *
  * @param string $form_name The name of the file in the form data
  *
  * @return null
  */
 protected function integrate_uploaded_file($form_name, $chunk, $file_path)
 {
     $is_multipart = $this->is_multipart();
     $upload = $this->request->file($form_name);
     if ($is_multipart && (!isset($upload['tmp_name']) || !is_uploaded_file($upload['tmp_name']))) {
         $this->emit_error(103, 'PLUPLOAD_ERR_MOVE_UPLOADED');
     }
     $tmp_file = $this->temporary_filepath($upload['tmp_name']);
     if (!phpbb_is_writable($this->temporary_directory) || !move_uploaded_file($upload['tmp_name'], $tmp_file)) {
         $this->emit_error(103, 'PLUPLOAD_ERR_MOVE_UPLOADED');
     }
     $out = fopen("{$file_path}.part", $chunk == 0 ? 'wb' : 'ab');
     if (!$out) {
         $this->emit_error(102, 'PLUPLOAD_ERR_OUTPUT');
     }
     $in = fopen($is_multipart ? $tmp_file : 'php://input', 'rb');
     if (!$in) {
         $this->emit_error(101, 'PLUPLOAD_ERR_INPUT');
     }
     while ($buf = fread($in, 4096)) {
         fwrite($out, $buf);
     }
     fclose($in);
     fclose($out);
     if ($is_multipart) {
         unlink($tmp_file);
     }
 }
Example #3
0
 /**
  * Form upload method
  * Upload file from users harddisk
  *
  * @param string $form_name Form name assigned to the file input field (if it is an array, the key has to be specified)
  *
  * @return filespec $file Object "filespec" is returned, all further operations can be done with this object
  * @access public
  */
 protected function form_upload($form_name)
 {
     $upload = $this->request->file($form_name);
     unset($upload['local_mode']);
     $result = $this->plupload->handle_upload($form_name);
     if (is_array($result)) {
         $upload = array_merge($upload, $result);
     }
     /** @var filespec $file */
     $file = $this->factory->get('filespec')->set_upload_ary($upload)->set_upload_namespace($this->upload);
     if ($file->init_error()) {
         $file->error[] = '';
         return $file;
     }
     // Error array filled?
     if (isset($upload['error'])) {
         $error = $this->upload->assign_internal_error($upload['error']);
         if ($error !== false) {
             $file->error[] = $error;
             return $file;
         }
     }
     // Check if empty file got uploaded (not catched by is_uploaded_file)
     if (isset($upload['size']) && $upload['size'] == 0) {
         $file->error[] = $this->language->lang($this->upload->error_prefix . 'EMPTY_FILEUPLOAD');
         return $file;
     }
     // PHP Upload file size check
     $file = $this->check_upload_size($file);
     if (sizeof($file->error)) {
         return $file;
     }
     // Not correctly uploaded
     if (!$file->is_uploaded()) {
         $file->error[] = $this->language->lang($this->upload->error_prefix . 'NOT_UPLOADED');
         return $file;
     }
     $this->upload->common_checks($file);
     return $file;
 }
Example #4
0
    public function avatar_upload_move_file($event)
    {
        if (!sizeof($event['error'])) {
            $row = $event['row'];
            /** Ignore */
            if ($row['id'] != $this->user->data['user_id']) {
                return false;
            }
            $upload_file = $this->request->file('avatar_upload_file');
            if (!empty($upload_file['name'])) {
                if ($result = $this->resize->avatar_upload_resize($row)) {
                    // Success! Lets save the result in the database
                    $result = array('user_avatar_type' => AVATAR_UPLOAD, 'user_avatar' => $result['avatar'], 'user_avatar_width' => $result['avatar_width'], 'user_avatar_height' => $result['avatar_height']);
                    $sql = 'UPDATE ' . USERS_TABLE . '
						SET ' . $this->db->sql_build_array('UPDATE', $result) . '
						WHERE user_id = ' . (int) $this->user->data['user_id'];
                    $this->db->sql_query($sql);
                    meta_refresh(3, build_url());
                    $message = $this->user->lang['PROFILE_UPDATED'] . '<br /><br />' . sprintf($this->user->lang['RETURN_PAGE'], '<a href="' . build_url() . '">', '</a>');
                    trigger_error($message);
                }
            }
        }
    }