图片上传
@return UploaderImageForm
@throws ServerErrorHttpException
@throws \yii\base\InvalidConfigException
@throws \Exception
488275
public function actionImage()
    {
        $model = new UploaderImageForm();
        $model->load(Yii::$app->getRequest()->getBodyParams(), '');
        if ($model->save() != false) {
            Yii::$app->getResponse()->setStatusCode(201);
            return $model;
        } elseif (!$model->hasErrors()) {
            throw new ServerErrorHttpException('Failed to create the object for unknown reason.');
        }
        return $model;
    }
726801
public function upload()
    {
        $path = request()->image->store(config('wink.storage_path'), [
                'disk' => config('wink.storage_disk'),
                'visibility' => 'public',
            ]
        );

        return response()->json([
            'url' => Storage::disk(config('wink.storage_disk'))->url($path),
        ]);
    }
550725
public function uploadAction ()
    { 
        $handle = $this->getRequest()->files->get('file');
        
        if ($handle && $handle->getError()){
            return new JsonResponse(array(
                'success' => false,
                'err_msg' => $this->container->get('translator')
                    ->trans('file_upload_http_error', array(), 'ThraceMediaBundle')
            ));
        }
        
        $fileManager = $this->container->get('thrace_media.filemanager');
        $extension = $handle->getClientOriginalExtension();
        $name = uniqid() . '.' . $extension;
        
        if(!$extension){
            return new JsonResponse(array(
                'success' => false,
                'err_msg' => sprintf('Unknown Mime Type: "%s"', $handle->getMimeType())
            ));
        }

        $validate = $this->validateFile($handle);

        if ($validate !== true) {
            return new JsonResponse(array(
                'success' => false,
                'err_msg' => $validate
            ));
        }
        
        $content = file_get_contents($handle->getRealPath());
        $fileManager->saveToTemporaryDirectory($name, $content);
        $hash = $fileManager->checksumTemporaryFileByName($name);

        return new JsonResponse(array(
            'success' => true,
            'name'    => $name,
            'hash'    => $hash,
        ));
        
    }
688349
public function uploadAction()
    {
        $request    = $this->getRequest();
        $locator    = $this->getServiceLocator();
        $model      = $locator->get( 'Grid\Paragraph\Model\Snippet\Model' );
        $snippet    = $model->create();
        $form       = $locator->get( 'Form' )
                              ->create( 'Grid\Paragraph\Snippet\Upload' );

        /* @var $form \Zend\Form\Form */
        $form->setHydrator( $model->getMapper() )
             ->bind( $snippet );

        if ( $request->isPost() )
        {
            $form->setData( ArrayUtils::merge(
                $request->getPost()->toArray(),
                $request->getFiles()->toArray()
            ) );

            if ( $form->isValid() &&
                 ( $form->getData()
                        ->getOption( 'overwrite' ) ||
                   $model->isNameAvailable( $snippet->name ) ) &&
                 $snippet->save() )
            {
                $this->messenger()
                     ->add( 'paragraph.form.snippet.success',
                            'paragraph', Message::LEVEL_INFO );

                return $this->redirect()
                            ->toRoute( 'Grid\Paragraph\Snippet\List', array(
                                'locale' => (string) $this->locale(),
                            ) );
            }
            else
            {
                $this->messenger()
                     ->add( 'paragraph.form.snippet.failed',
                            'paragraph', Message::LEVEL_ERROR );
            }
        }

        $form->setCancel(
            $this->url()
                 ->fromRoute( 'Grid\Paragraph\Snippet\List', array(
                        'locale' => (string) $this->locale(),
                    ) )
        );

        return array(
            'form'  => $form,
        );
    }
1296816
public function actionFilesUpload()
    {
        $this->checkRouteAccess(self::PERMISSION_ROUTE);
        
        foreach ($_FILES as $k => $file) {
            if ($file['error'] !== UPLOAD_ERR_OK) {
                Yii::$app->response->setStatusCode(422, 'Data Validation Failed.');
                return ['upload' => false, 'message' => Storage::getUploadErrorMessage($file['error']), 'file' => null];
            }
            try {
                $response = Yii::$app->storage->addFile($file['tmp_name'], $file['name'], Yii::$app->request->post('folderId', 0), Yii::$app->request->post('isHidden', false));
                if ($response) {
                    return ['upload' => true, 'message' => Module::t('api_storage_file_upload_succes'), 'file' => $response];
                } else {
                    Yii::$app->response->setStatusCode(422, 'Data Validation Failed.');
                    return ['upload' => false, 'message' => Module::t('api_storage_file_upload_folder_error'), 'file' => null];
                }
            } catch (Exception $err) {
                Yii::$app->response->setStatusCode(422, 'Data Validation Failed.');
                return ['upload' => false, 'message' => Module::t('api_sotrage_file_upload_error', ['error' => $err->getMessage()]), 'file' => null];
            }
        }
    
        // If the files array is empty, this is an indicator for exceeding the upload_max_filesize from php ini or a wrong upload defintion.
        Yii::$app->response->setStatusCode(422, 'Data Validation Failed.');
        return ['upload' => false, 'message' => Storage::getUploadErrorMessage(UPLOAD_ERR_NO_FILE), 'file' => null];
    }
138268
public function upload()
    {
        $this->morphOne(Upload::class, 'uploadable');
        $this->htmlType('upload');
        $this->where('z_uploads.type', $this->getName());
        $this->addVueEditorComponent('UploadComponent',
            config('scaffold.frontend_folder', 'frontend') . '/Upload/resources/assets/Components/Upload.vue');
        return $this;
    }
514858
public function upload()
    {
        // upload the photo here
        $attributes = request()->validate(Document::$rules);

        // get the documentable
        $documentable = input('documentable_type')::find(input('documentable_id'));

        if (!$documentable) {
            return json_response_error('Whoops', 'We could not find the documentable.');
        }

        // move and create the photo
        $photo = $this->moveAndCreateDocument($attributes['file'], $documentable);

        if (!$photo) {
            return json_response_error('Whoops', 'Something went wrong, please try again.');
        }

        return json_response(['id' => $photo->id]);
    }
85035
public function upload()
    {
        $album = $this->request->getQuery('album');
        $albums = $this->viewVars['albums']->toArray();

        //If there's only one available album
        if (!$album && count($albums) < 2) {
            $album = array_key_first($albums);
            $this->request = $this->request->withQueryParams(compact('album'));
        }

        if ($this->request->getData('file')) {
            is_true_or_fail($album, __d('me_cms', 'Missing ID'), InternalErrorException::class);

            $uploaded = $this->Uploader->set($this->request->getData('file'))
                ->mimetype('image')
                ->save(PHOTOS . $album);

            if (!$uploaded) {
                return $this->setUploadError($this->Uploader->getError());
            }

            $entity = $this->Photos->newEntity([
                'album_id' => $album,
                'filename' => basename($uploaded),
            ]);

            if ($entity->getErrors()) {
                return $this->setUploadError(array_value_first_recursive($entity->getErrors()));
            }

            if (!$this->Photos->save($entity)) {
                $this->setUploadError(I18N_OPERATION_NOT_OK);
            }
        }
    }
588123
public function actionBindMobile()
    {
        $model = new UserBindMobileForm();
        $model->load(Yii::$app->getRequest()->getBodyParams(), '');
        if (($user = $model->bind()) != false) {
            Yii::$app->getResponse()->setStatusCode(200);
            return $user;
        } elseif (!$model->hasErrors()) {
            throw new ServerErrorHttpException('Failed to create the object for unknown reason.');
        }
        return $model;
    }
1087553
public function actionAvatar()
    {
        $model = new AvatarForm();
        $model->load(Yii::$app->getRequest()->getBodyParams(), '');
        if (($model->save()) !== false) {
            Yii::$app->getResponse()->setStatusCode(200);
            return $model;
        } elseif (!$model->hasErrors()) {
            throw new ServerErrorHttpException('Failed to create the object for unknown reason.');
        }
        return $model;
    }
546998
protected function buildImageCrop () {
    $image = Image::make($this->upload_path . $this->file_name)->orientate();

    if ($this->preset->width == 0) {
      $image->heighten($this->preset->height);
    }
    else if ($this->preset->height == 0) {
      $image->widen($this->preset->width);
    }
    else {
      $image->fit($this->preset->width, $this->preset->height);
    }

    return $image;
  }
364467
public function actionRecovery()
    {
        $model = new UserRecoveryForm();
        $model->load(Yii::$app->getRequest()->getBodyParams(), '');
        if ($model->resetPassword()) {
            Yii::$app->getResponse()->setStatusCode(200);
        } elseif (!$model->hasErrors()) {
            throw new ServerErrorHttpException('Failed to create the object for unknown reason.');
        }
        return $model;
    }
616825
public function actionCreate()
    {
        $form = new DomainForm();
        if ($form->load(Yii::$app->request->post()) && $form->validate()) {
            try {
                $model = $this->service->create($form);
                return $this->redirect(['view', 'id' => $model->id]);
            } catch (\DomainException $e) {
                Yii::$app->errorHandler->logException($e);
                Yii::$app->session->setFlash('error', $e->getMessage());
            }
        }
        return $this->render('create', [
            'model' => $form,
        ]);
    }
1285323
public function fileUpload()
    {
        $this->element = Angular::fileUpload('{model}', '{label}', [
            'fieldid' => $this->form->getFieldId($this->attribute),
            'ng-init' => '{initValue}',
        ]);

        return $this;
    }
511816
public function upload()
    {
        $multipartStream = new Psr7\MultipartStream([
            [
                'name' => 'metadata',
                'headers' => ['Content-Type' => 'application/json; charset=UTF-8'],
                'contents' => $this->jsonEncode($this->metadata)
            ],
            [
                'name' => 'data',
                'headers' => ['Content-Type' => $this->contentType],
                'contents' => $this->data
            ]
        ], 'boundary');

        $headers = [
            'Content-Type' => 'multipart/related; boundary=boundary',
            'Content-Length' => $multipartStream->getSize()
        ];

        return $this->jsonDecode(
            $this->requestWrapper->send(
                new Request(
                    'POST',
                    $this->uri,
                    $headers,
                    $multipartStream
                ),
                $this->requestOptions
            )->getBody(),
            true
        );
    }
1114785
public function uploadFile()
	{
        if (!isset(Yii::app()->params['ciims_plugins']['upload']))
        {
            Yii::import('cii.utilities.CiiFileUploader');
            $className = 'CiiFileUploader';
        }
        else
            $className = Yii::app()->params['ciims_plugins']['upload']['class'];

        $config = isset(Yii::app()->params['ciims_plugins']['upload']['options']) ? Yii::app()->params['ciims_plugins']['upload']['options'] : array();
        $class = new $className($config);
        $this->_result = $class->upload();
        $this->_response = $this->_handleResourceUpload($this->_result['url']);

        return $this->_response;
	}
629844
public function actionFileUpload() {

		$source = $this->config->getCompatibleSource($this->request->source);

		$root = $source->getRoot();
		$path = $source->getPath();

		$this->accessControl->checkPermission($this->getUserRole(), $this->action, $path);

		$messages = [];

		$files = $this->move($source);

		$isImages = [];
		$files = array_map(function (File $file) use ($source, $root, &$isImages) {
			$messages[] = 'File ' . $file->getName() . ' was uploaded';
			$isImages[] = $file->isImage();
			return str_replace($root, '', $file->getPath());
		}, $files);

		if (!count($files)) {
			throw new \Exception('No files have been uploaded', Consts::ERROR_CODE_NO_FILES_UPLOADED);
		}

		return [
			'baseurl' => $source->baseurl,
			'messages' => $messages,
			'files' => $files,
			'isImages' => $isImages
		];
	}