Upload a picture to Cloudinary.

@param SplFileInfo $file     The file to upload.
@param string      $publicId Path where to upload in Cloudinary.

@return array
11125
protected function uploadFileToCloudinary($file, $publicId)
    {
        $result = $this->uploader->upload(
            $file->getRealPath(),
            [
                'public_id' => $publicId,
            ]
        );

        return $result;
    }
535727
public function insert($bucketId, $file, $fileName)
    {
        $this->ensureAuthorized();
        if(!$this->downloadToken || !$this->uploadURL){
            $response = $this->client->b2GetUploadURL($this->apiURL, $this->token, $bucketId);
            if ($response->isOk()) {
                $this->downloadToken = $response->get('authorizationToken');
                $this->uploadURL     = $response->get('uploadUrl');
            }else{
                return false;
            }
        }
        $response2 = $this->client->b2UploadFile($file, $this->uploadURL, $this->downloadToken, $fileName);
        if ($response2->isOk()) {
            return $response2->getData();
        }else{
            // b2_get_upload_url returns an upload authorization token. This token lasts at most 24 hours.
            // However, it is only valid to upload data to one storage pod. If that pod is offline, full or overloaded,
            // a request to b2_upload_file again.
            $response = $this->client->b2GetUploadURL($this->apiURL, $this->token, $bucketId);
            if ($response->isOk()) {
                $this->downloadToken = $response->get('authorizationToken');
                $this->uploadURL     = $response->get('uploadUrl');
                $this->client->b2UploadFile($file, $this->uploadURL, $this->downloadToken, $fileName);
                if ($response2->isOk()) {
                    return $response2->getData();
                }
            }
        }

        return false;
    }
140026
private function imageAndFileOutput(File $file, $localeId = null)
	{
		$request = $this->container->getRequest();
		$postInput = $request->isMethod('POST') ? $request->request : $request->query;
		$requestedSizes = $postInput->get('sizes', array());
		$requestedSizeNames = array();
		$isBroken = false;
		$thumbSize = null;
		$previewSize = null;

		try {
			if ($file instanceof Image && $this->getFileStorage()->fileExists($file)) {

				$thumbSize = $this->getFileStorage()->createResizedImage($file, 30, 30, true);
				$previewSize = $this->getFileStorage()->createResizedImage($file, 200, 200);

				foreach ($requestedSizes as $size) {
					$width = filter_var($size['width'], FILTER_VALIDATE_INT);
					$height = filter_var($size['height'], FILTER_VALIDATE_INT);
					$crop = filter_var($size['crop'], FILTER_VALIDATE_BOOLEAN);

					$requestedSizeNames[] = $this->getFileStorage()->createResizedImage($file, $width, $height, $crop);
				}
			}
		} catch (\Exception $e) {
			$isBroken = true;
		}

		$output = $this->getFileStorage()->getFileInfo($file, $localeId);

		// Return only requested sizes
		if ( ! empty($requestedSizeNames)) {
			foreach ($output['sizes'] as $sizeName => $size) {

				if ($sizeName == 'original') {
					continue;
				}

				if ( ! in_array($sizeName, $requestedSizeNames, true)) {
					unset($output['sizes'][$sizeName]);
				}
			}
		}

		// Create thumbnail&preview
		try {
			if ($file instanceof Image && $this->getFileStorage()->fileExists($file)) {
				if ($file->isPublic()) {
					$output['preview'] = $this->getFileStorage()->getWebPath($file, $previewSize);
					$output['thumbnail'] = $this->getFileStorage()->getWebPath($file, $thumbSize);
				} else {
					$output['thumbnail'] = $this->getPrivateImageWebPath($file, $thumbSize);
					$output['file_web_path'] = $output['preview'] = $this->getPrivateImageWebPath($file);

					if ( ! empty($output['sizes'])) {
						foreach ($output['sizes'] as $sizeName => &$size) {
							$sizePath = null;

							if ($sizeName == 'original') {
								$sizePath = $output['file_web_path'];
							} else {
								$sizePath = $this->getPrivateImageWebPath($file, $sizeName);
							}

							$size['external_path'] = $sizePath;
						}
					}
				}
			}
		} catch (\Exception $e) {
			$output['broken'] = true;
			return $output;
		}

		$extension = mb_strtolower($file->getExtension());
		$knownExtensions = $this->container->getParameter('cms.media_library_known_file_extensions');
		if (in_array($extension, $knownExtensions)) {
			$output['known_extension'] = $extension;
		}

		$checkExistance = $this->container->getParameter('cms.media_library_check_file_existence');

		if ($isBroken) {
			$output['broken'] = true;
		} elseif ($checkExistance == self::CHECK_FULL
			|| $checkExistance == self::CHECK_PARTIAL) {

			$output['broken'] = ( ! $this->isAvailable($file));
		}

		$output['timestamp'] = $file->getModificationTime()->getTimestamp();

		// Custom Properties
		$propertyConfigurations = $this->getFileStorage()->getCustomPropertyConfigurations();
		$propertyData = array();
		foreach ($propertyConfigurations as $configuration) {
			/* @var $configuration PropertyConfiguration */
			$propertyName = $configuration->name;
			$propertyData[$propertyName] = $this->getFileStorage()->getFileCustomPropertyValue($file, $propertyName);
		}

		$output['metaData'] = $propertyData;

		return $output;
	}
1174627
public function filter(\SplFileInfo $file)
    {
        try {
            $class = $this->getClassName($file->getPathname());
        } catch (\Exception $e){
            return false;
        }

        if (! @include_once($file->getPathname())) {
            return false;
        }

        $ReflectionClass = new \ReflectionClass($class);

        foreach ($this->instances as $instance) {
            if ($ReflectionClass->isSubclassOf($instance)) {
                return true;
            }

            if ($class === $instance) {
                return true;
            }
        }

        return false;
    }
1371449
public function upload($file) {

        if (is_array($file['name'])) {
            $files = $this->reArrayFiles($file);

            $results = [];

            foreach ($files as $singleFile) {
                $result = $this->uploadSingle($singleFile);

                $results[] = $result;
            }

            return $results;

        } else {

            return Array($this->uploadSingle($file));

        }
    }
1077082
public static function upload($file)
    {
        $photo = self::create();

        $image_manager = new ImageManager(['driver' => 'imagick']);

        $disk = Storage::disk(config('mustard.storage.disk', 'local'));

        if (!file_exists($file)) {
            RuntimeException("File $file does not exist");
        }

        $dest_dir = config('mustard.storage.photo.dir', 'mustard/photos');
        $quality = config('mustard.storage.photo.quality', 90);

        $disk->makeDirectory($dest_dir);

        $photo_id = $photo->getKey();

        Queue::push(function ($job) use ($file, $quality, $dest_dir, $photo_id) {
            if (!file_exists($file)) {
                RuntimeException("File $file no longer exists");
            }

            $image_manager = new ImageManager(['driver' => 'imagick']);

            $disk = Storage::disk(config('mustard.storage.disk', 'local'));

            if ($file != "$dest_dir/$photo_id.jpg") {
                $image = $image_manager->make($file);

                $disk->put("$dest_dir/$photo_id.jpg", (string) $image->encode('jpg', $quality));

                $image->destroy();
            }

            $image = $image_manager->make($file)->heighten(83);

            $disk->put("$dest_dir/{$photo_id}_s.jpg", (string) $image->encode('jpg', $quality));

            $image->destroy();

            $image = $image_manager->make($file)->widen(500);

            $disk->put("$dest_dir/{$photo_id}_l.jpg", (string) $image->encode('jpg', $quality));

            $image->destroy();

            $photo = Photo::find($photo_id);

            $photo->processed = true;

            $photo->save();

            $job->delete();
        });

        return $photo;
    }
836371
public static function createFromSplFileInfo(\SplFileInfo $file)
    {
        $asset = new Asset();
        $guesser = MimeTypeGuesser::getInstance();
        return $asset
            ->setFilename($file->getFilename())
            ->setExtension($file->getExtension())
            ->setPathname($file->getPathname())
            ->setMimeType($guesser->guess($file->getPathname()))
            ->setClientOriginalName($file->getFilename())
            ->setClientOriginalExtension($file->getExtension())
        ;
    }
1129569
protected function getFilePieces(\SplFileInfo $file)
    {
        $key = $file->getBasename();
        if (!array_key_exists($key, $this->filePieces)) {
            $pieces = explode('.', $file->getBasename());
            if (count($pieces) < 3) {
                return true;
            }
            $extension = array_pop($pieces);
            $locale = array_pop($pieces);
            $domain = implode('.', $pieces);

            $this->filePieces[$key] = [
                self::FILE_PIECE_DOMAIN => $domain,
                self::FILE_PIECE_LOCALE => $locale,
                self::FILE_PIECE_EXTENSION => $extension,
            ];
        }

        return $this->filePieces[$key];
    }
286618
public static function uploadsInternal($file = null)
    {
        return base_path(
            self::appendToPath(
                self::appendToPath(config('pxlcms.paths.base_internal'), config('pxlcms.paths.files')),
                $file
            )
        );
    }
219059
public function fixFile(SplFileInfo $file)
    {
        $filePath = $file->getRealPath();

        $image = $this->imagine->open($file->getRealPath());

        $image = $this->fixImage($filePath, $image);
        $image->save();

        return true;
    }
145985
public static function upload($filePath, $bucket, $fileid = '', $userid = 0, $magicContext = '', $params = array()) {
        if (!file_exists($filePath)) {
            return array('httpcode' => 0, 'code' => self::IMAGE_FILE_NOT_EXISTS, 'message' => 'file '.$filePath.' not exists', 'data' => array());
        }

        return self::upload_impl($filePath, 0, $bucket, $fileid, $userid, $magicContext, $params);
    }
159211
private function doRequestUpload(UploadedFile $file)
    {
        $tmpDirectory = $this->getApplication()->getTemporaryDir();
        $data = [];

        if (null !== $file) {
            if ($file->isValid()) {
                if ($file->getClientSize() <= $file->getMaxFilesize()) {
                    $data = $this->buildData($file->getClientOriginalName(), $file->guessExtension());
                    $file->move($tmpDirectory, $data['filename']);
                    $data['size'] = round($file->getClientSize() / 1024, 2);
                    if ($imageInfo = @getimagesize( $data['path'])) {
                        if (isset($imageInfo[0]) && isset($imageInfo[1])) {
                            $data['width'] = $imageInfo[0];
                            $data['height'] = $imageInfo[1];
                        }
                    } else {
                        $data['width'] = 0;
                        $data['height'] = 0;
                    }
                } else {
                    throw new BadRequestHttpException('Too big file, the max file size is ' . $file->getMaxFilesize());
                }
            } else {
                throw new BadRequestHttpException($file->getErrorMessage());
            }
        }

        return $data;
    }
646936
protected function validateUpload(UploadedFileInterface $file): void
    {
        // Handle bad filenames.
        $filename = $file->getClientFilename();

        if (!Utils::checkFilename($filename)) {
            $grav = Grav::instance();
            throw new \RuntimeException(
                sprintf($grav['language']->translate('PLUGIN_FORM.FILEUPLOAD_UNABLE_TO_UPLOAD', null, true), $filename, 'Bad filename')
            );
        }
    }
998445
private function uploadOne(UploadedFile $file)
    {
        try {
            $uploader = new Uploader(['config' => $this->_config]);
            $uploader->up($file);
            $fileInfo = $uploader->getFileInfo();
            $result = [
                'name' => Html::encode($file->name),
                'url' => $fileInfo['url'],
                'path' => $fileInfo['url'],
                'extension' => $file->extension,
                'type' => $file->type,
                'size' => $file->size
            ];
            if ($this->onlyImage !== true) {
                $result['filename'] = $result['name'];
            }

        } catch (Exception $e) {
            $result = [
                'error' => $e->getMessage()
            ];
        }
        return $result;
    }
197861
private function getFileContents(SplFileInfo $file)
    {
        $content = $file->getContents();
        if ($file->getExtension() === 'js' && substr($content, -1) !== ';') {
            $content .= ';';
        }

        return $content;
    }
631764
public function saveFile($containerName, \SplFileInfo $file, $relativePath)
    {
        return $this->fileUploadFacade->saveFile($containerName, $file, $relativePath);
    }
732259
protected function normalizeFileInfo(SplFileInfo $file)
    {
        if ( ! $file->isLink()) {
            return $this->mapFileInfo($file);
        }

        if ($this->linkHandling & self::DISALLOW_LINKS) {
            throw NotSupportedException::forLink($file);
        }
    }