Upload the active image on the livedocx server

@return Image

@throws UploadException
@throws FileExistException
554034
public function upload()
    {
        $filename = $this->getName(true);

        if ( ! is_readable($filename) ) {
            throw new FileExistException('Image file from disk is not readable');
        }

        try {
            $this->getSoapClient()->UploadImage(array(
                'image'    => base64_encode(file_get_contents($filename)) ,
                'filename' => basename($filename) ,
            ));

            return $this;
        } catch ( SoapException $e ) {
            throw new UploadException('Error while uploading the image' , $e);
        }
    }
1020504
public function doUpload()
    {
        // CJ: Create a folder if it doesn't already exist
        if (!file_exists($this->getOption('location'))) {
            mkdir($this->getOption('location'), 0777, true);
        }

        //use the multup library to perform the upload
        $result = Multup::open('file', 'image|max:'.$this->getOption('size_limit') * 1000, $this->getOption('location'),
                                    $this->getOption('naming') === 'random')
            ->sizes($this->getOption('sizes'))
            ->set_length($this->getOption('length'))
            ->upload();

        return $result[0];
    }
923529
public String uploadImage(byte[] image, byte[] watermark, String ext, Map<String, String> metaInfo) {
        return uploadImage(image, watermark, ext, metaInfo, DEFAULT_OPACITY, DEFAULT_LOCATION, DEFAULT_MARGIN);
    }
34124
public function upload()
    {
        $position = $this->request->getQuery('position');
        $positions = $this->viewVars['positions']->toArray();

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

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

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

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

            $entity = $this->Banners->newEntity([
                'position_id' => $position,
                'filename' => basename($uploaded),
            ]);

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

            if (!$this->Banners->save($entity)) {
                $this->setUploadError(I18N_OPERATION_NOT_OK);
            }
        }
    }
270693
private void uploadImage(long txid) throws IOException {
    final long start = AvatarNode.now();
    LOG.info("Standby: Checkpointing - Upload fsimage to remote namenode.");
    checkpointStatus("Image upload started");
    
    imageUploader = new ImageUploader(txid);
    imageUploader.start();
    
    // wait for the upload to complete   
    while (running
        && !imageUploader.done
        && AvatarNode.now() - start < MAX_CHECKPOINT_UPLOAD_TIMEOUT) {
      try {
        imageUploader.join(3000);
      } catch (InterruptedException ie) { 
        LOG.error("Reveived interruption when uploading image for txid: "
            + txid);
        Thread.currentThread().interrupt();
        throw (IOException) new InterruptedIOException().initCause(ie);
      } 
    }
    if (!running || !imageUploader.succeeded) {
      InjectionHandler.processEvent(InjectionEvent.STANDBY_UPLOAD_FAIL);
      throw new IOException(
          "Standby: Checkpointing - Image upload failed (time= "
              + (AvatarNode.now() - start) + " ms).", imageUploader.error);
    }
    imageUploader = null;
    LOG.info("Standby: Checkpointing - Upload fsimage to remote namenode DONE.");
    checkpointStatus("Image upload completed");
  }
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;
  }
377725
public function imageupload(){
		if (!Member::currentUserID()) {
			$return = array(
				'error' => 1,
				'text' => "Cannot upload there"
			);
			return Convert::raw2json($return);
		}
		if(isset($_FILES['NewImage']) && $tempfile = $_FILES['NewImage']){
			// validate //
			
			$allowed = array('jpg', 'jpeg', 'gif', 'png', 'ico');
			$nameBits = explode('.', $tempfile['name']);
			$ext = end($nameBits);
			if(!in_array(strtolower($ext), $allowed)){
				$return = array(
					'error' => 1,
					'text' => "Your image must be in jpg, gif or png format"
				);
				return Convert::raw2json($return);
			}
			
			$maxsize = $_POST['MAX_FILE_SIZE'];
			if($tempfile['size'] > $maxsize){
				$size = number_format($maxsize / 1024 / 1024, 2) . 'MB'; 
				$return = array(
					'error' => 1,
					'text' => "Your image must be smaller than $size"
				);
				return Convert::raw2json($return);
			}
			
			// upload //
			
			$upload	= new Upload;
			$file = new Image();
			$upload->loadIntoFile($tempfile, $file);
			if($upload->isError()) 
				return false;
			$file = $upload->getFile();
			$return =  array(
				'link' => $file->Link()
			);
			return Convert::raw2json($return);
		
		}else{
		 	// no file to upload
			return false;
		}
	}
157113
public function upload()
    {
        // validate that all options properties was properly set to correct type.
        $this->validateOptionsProperties();
        // setup file extensions and mime types for validation. (in case that it was not set).
        $this->setupFileExtensionsMimeTypesForValidation();

        // verify that location where the uploaded file(s) will be moved to is writable.
        if (!is_dir($this->move_uploaded_to)) {
            $this->setErrorMessage(
                static::__('The target location where the uploaded file(s) will be moved to is not folder or directory.'),
                'RDU_MOVE_UPLOADED_TO_NOT_DIR',
                $this->move_uploaded_to
            );
            return false;
        } elseif (is_dir($this->move_uploaded_to) && !is_writable($this->move_uploaded_to)) {
            $this->setErrorMessage(
                static::__('The target location where the uploaded file(s) will be moved to is not writable. Please check the folder permission.'),
                'RDU_MOVE_UPLOADED_TO_NOT_WRITABLE',
                $this->move_uploaded_to
            );
            return false;
        } else {
            // solve the move uploaded to as a real path.
            $this->move_uploaded_to = realpath($this->move_uploaded_to);
        }

        if (isset($_FILES[$this->input_file_name]['name']) && is_array($_FILES[$this->input_file_name]['name'])) {
            // if multiple file upload.
            foreach ($_FILES[$this->input_file_name]['name'] as $key => $value) {
                $this->files[$this->input_file_name]['input_file_key'] = $key;
                $this->files[$this->input_file_name]['name'] = $_FILES[$this->input_file_name]['name'][$key];
                $this->files[$this->input_file_name]['type'] = (isset($_FILES[$this->input_file_name]['type'][$key]) ? $_FILES[$this->input_file_name]['type'][$key] : null);
                $this->files[$this->input_file_name]['tmp_name'] = (isset($_FILES[$this->input_file_name]['tmp_name'][$key]) ? $_FILES[$this->input_file_name]['tmp_name'][$key] : null);
                $this->files[$this->input_file_name]['error'] = (isset($_FILES[$this->input_file_name]['error'][$key]) ? $_FILES[$this->input_file_name]['error'][$key] : 4);
                $this->files[$this->input_file_name]['size'] = (isset($_FILES[$this->input_file_name]['size'][$key]) ? $_FILES[$this->input_file_name]['size'][$key] : 0);

                $result = $this->uploadSingleFile();

                if ($result == false && $this->stop_on_failed_upload_multiple === true) {
                    // it was set to sop on failed to upload multiple file. return false.
                    unset($result);
                    return false;
                }
            }// endforeach;
            unset($key, $value);
        } else {
            // if single file upload.
            $this->files[$this->input_file_name] = $_FILES[$this->input_file_name];
            $this->files[$this->input_file_name]['input_file_key'] = 0;

            $result = $this->uploadSingleFile();
        }

        if (isset($result) && $result == false && $this->stop_on_failed_upload_multiple === true) {
            // there is at lease one upload error and it was set to stop on error.
            unset($result);
            $this->clearUploadedAtTemp();
            return false;
        } elseif (count($this->error_messages) > 0 && $this->stop_on_failed_upload_multiple === true) {
            // there is at lease one upload error and it was set to stop on error.
            unset($result);
            $this->clearUploadedAtTemp();
            return false;
        }

        return $this->moveUploadedFiles();
    }
1133024
protected function getUploadedImage()
    {
        if ($this->getMappingResultsForProperty()->hasErrors()) {
            return null;
        }
        $image = $this->getPropertyValue();
        if ($image instanceof Image) {
            return $image;
        }
        return $this->propertyMapper->convert($this->getValueAttribute(), Image::class);
    }
1056941
public function resolve()
    {
        $this->setFile($this->fileDomain->upload(
            $this->sourceFile
        ));
        if (!$this->name) {
            $this->setName($this->getFile()->getOriginalName());
        }

        return parent::resolve();
    }
1009552
public function upload()
    {
        $files = request()->file('file');
        $error_bag = [];
        foreach (is_array($files) ? $files : [$files] as $file) {
            $validation_message = $this->uploadValidator($file);
            $new_filename = $this->proceedSingleUpload($file);

            if ($validation_message !== 'pass') {
                array_push($error_bag, $validation_message);
            } elseif ($new_filename == 'invalid') {
                array_push($error_bag, $response);
            }
        }

        if (is_array($files)) {
            $response = count($error_bag) > 0 ? $error_bag : parent::$success_response;
        } else { // upload via ckeditor 'Upload' tab
            $response = $this->useFile($new_filename);
        }

        return $response;
    }
837340
public function upload()
    {
        $params = $this->getUploadParams();

        if ($params) {
            $class = $this->class;
            $uri = $class::getUri();
            $document = static::post($this->client, $uri, $params);

            /** @var Model $instance */
            $instance = new $this->class($this->client, $document);
            $instance->exists = true;
            $instance->cacheFields($document);
            return $instance;
        }

        return null;
    }
671231
public function uploadAction()
    {
        $request = $this
            ->requestStack
            ->getCurrentRequest();

        /**
         * @var UploadedFile $file
         */
        $file = $request
            ->files
            ->get($this->uploadFieldName);

        if (!($file instanceof UploadedFile)) {
            return new JsonResponse([
                'status' => 'ko',
                'response' => [
                    'message' => 'Image not found',
                ],
            ]);
        }

        try {
            $image = $this
                ->imageUploader
                ->uploadImage($file);

            $routes = $this
                ->router
                ->getRouteCollection();

            $response = [
                'status' => 'ok',
                'response' => [
                    'id' => $image->getId(),
                    'extension' => $image->getExtension(),
                    'routes' => [
                        'view' => $routes
                            ->get($this->viewImageRouteName)
                            ->getPath(),
                        'resize' => $routes
                            ->get($this->resizeImageRouteName)
                            ->getPath(),
                    ],
                ],
            ];
        } catch (Exception $exception) {
            $response = [
                'status' => 'ko',
                'response' => [
                    'message' => $exception->getMessage(),
                ],
            ];
        }

        return new JsonResponse($response);
    }
1802
protected function uploadFile($options)
    {
        if ( $options['type'] === 'file' ) {
            $this->repo = new FileRepository($options);
            $this->hasFile = true;
        } else {
            $this->repo = new ImageRepository($options);
            $this->hasPhoto = true;
        }

        if ( ! $this->repo->upload($this->model, $this->request) ) {
            return false;
        }

        return $this->repo->getDatas($this->request);
    }
443731
public function imageChangeByUpload()
    {
        $formName = $this->owner->formName();
        if (!empty($_POST[$formName][$this->imageAttribute]) && $_POST[$formName][$this->imageAttribute] == 'empty') {
            // reset image
            $this->imageReset();
        } else {
            // upload new
            if (!empty($_FILES[$formName]['tmp_name'][$this->imageAttribute])) {
                $this->imageChange(
                    [$_FILES[$formName]['name'][$this->imageAttribute] => $_FILES[$formName]['tmp_name'][$this->imageAttribute]]
                );
            }
        }
    }
928953
public function file() {
        $this->check_role = 'file';
        if (!$this->value) {
            $result = false;
        } else if ($this->value instanceof File) {
            $result = is_file($this->value->path_tmp);
        } else {
            $result = is_file($this->value);
        }
        $this->checkResult($result);
        return $this;
    }
726167
public function actionFile()
    {
        $model = new UploaderFileForm();
        $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;
    }