Mueve un arcivo subido
@param UploadedFile $file
@param string $path
@return SplFileInfo|null
508385
public function upload($file,$path){
        if( $this->validExt($file->getClientOriginalName())){
            if($file->getClientSize() > ($this->getMaxUploadFileSize() * 1024 * 1024) ){

                $result = array("query"=>"BE_UPLOAD_FILE_SIZE_NOT_SERVER","params"=>array($file->getClientSize()));
                $this->setInfo(array("msg"=>$result));

                if( $this->config['debug'] ) $this->_log(__METHOD__." - file size no permitido server: ".$file->getClientSize());
                return ;
            }elseif($file->getClientSize() > ($this->config['upload']['size_max'] * 1024 * 1024) ){

                $result = array("query"=>"BE_UPLOAD_FILE_SIZE_NOT_PERMITIDO","params"=>array($file->getClientSize()));
                $this->setInfo(array("msg"=>$result));

                if( $this->config['debug'] ) $this->_log(__METHOD__." - file size no permitido: ".$file->getClientSize());
                return ;
            }else{
                if($file->isValid()){
                    $dir = $this->getFullPath().$path;
                    $namefile = $file->getClientOriginalName();
                    $namefile = $this->clearNameFile($namefile);
                    $nametemp = $namefile;
                    if( $this->config["upload"]["overwrite"] ==false){
                        $ext = $this->getExtension($namefile);
                        $i=0;
                        while(true){
                            $pathnametemp = $dir.$nametemp;
                            if(file_exists($pathnametemp)){
                                $i++;
                                $nametemp = $this->removeExtension( $namefile ) . '_' . $i . '.' . $ext ;
                            }else{
                                break;
                            }
                        }
                    }
                    $file->move($dir,$nametemp);
                    $file = new  \SplFileInfo($dir.$nametemp);
                    return $file;
                }
            }
        }else{
            if( $this->config['debug'] ) $this->_log(__METHOD__." - file extension no permitido: ".$file->getExtension());
        }
    }
1055252
protected function upload(UploadedFile $file)
    {
        $this->renameIfExists($file);

        return $this->storage->putFileAs($this->getDirectory(), $file, $this->name);
    }
1064552
public function uploadImage(UploadedFile $file)
    {
        $image = $this
            ->imageManager
            ->createImage($file);

        $this
            ->mediaEventDispatcher
            ->dispatchImagePreUploadEvent($image);

        $this->imageObjectManager->persist($image);
        $this->imageObjectManager->flush($image);

        $this->fileManager->uploadFile(
            $image,
            file_get_contents($file->getRealPath()),
            true
        );

        $this
            ->mediaEventDispatcher
            ->dispatchImageOnUploadEvent($image);

        return $image;
    }
433662
public static function createFromUploadedFile(UploadedFile $file)
    {
        $size = getimagesize($file->getRealPath());

        $image = new Image($file->guessExtension());
        $image->setOriginalFilename($file->getClientOriginalName());
        $image->setMimeType($file->getMimeType());
        $image->setSize(filesize($file->getRealPath()));
        $image->setWidth($size[0]);
        $image->setHeight($size[1]);

        return $image;
    }
286717
protected static function findFile($file, array $paths)
    {
        if ($file === null) {
            return null;
        }
        foreach ($paths as $path) {
            $files = glob("$path/$file");
            if (!empty($files)) {
                return $files[0];
            }
        }
    }
1208157
public function setFile(File $file = null)
    {
        $this->file = $file;
        // Until php7/uploaderbundle 1.7
        if ($file instanceof UploadedFile) {
            $this->setMimeType($file->getMimeType());
            $this->setName($file->getClientOriginalName());
            $this->setSize($file->getSize());
        }
        
        return $this;
    }
651436
public function filter(\SplFileInfo $file)
    {
        foreach ($this->filter as $filter) {
            if ($filter->filter($file)) {
                return true;
            }
        }
        return false;
    }
830888
public static function process($uploadedFile, $path)
    {
        if (!$uploadedFile || $uploadedFile->hasError) {
            throw new Exception('Failed to upload file');
        }
        $chunk = (int)Yii::$app->request->getBodyParam('chunk', 0);
        $totalChunks = (int)Yii::$app->request->getBodyParam('chunks', 0);
        $out = fopen("$path.part", $chunk == 0 ? 'wb' : 'ab');
        if (!$out) {
            throw new Exception('Failed to open output stream');
        }
        // Read binary input stream and append it to temporary .part file
        $in = fopen($uploadedFile->tempName, 'rb');
        if ($in) {
            while ($buff = fread($in, 4096)) {
                fwrite($out, $buff);
            }
        } else {
            throw new Exception('Failed to open input stream');
        }
        fclose($in);
        fclose($out);
        unlink($uploadedFile->tempName);
        // Check if all chunks have been processed
        if (!$totalChunks || $chunk == $totalChunks - 1) {
            // Strip the temp .part suffix off
            rename("$path.part", $path);
            return true;
        }
        return false;
    }
1172929
public function getUploadFileName(UploadedFile $file)
    {
        if (is_callable($this->uploadFileNameRule)) {
            return call_user_func($this->uploadFileNameRule, $file);
        }

        return $this->getDefaultFileName($file);
    }
1015881
protected function prepareForeach(UploadedFile $file = null)
    {
        $self       = clone $this;
        $self->name = $self->getStoreName($file);

        return tap($self->upload($file), function () use ($self) {
            $self->name = null;
        });
    }
1276778
public function uploadBanner($file, $path = '', $size = ['o' => [1900, 500], 'tn' => [450, 212]])
    {
        $name = token();
        $extension = $file->guessClientExtension();

        $filename = $name . '.' . $extension;
        $filenameThumb = $name . '-tn.' . $extension;
        $imageTmp = Image::make($file->getRealPath());

        if (!$imageTmp) {
            return notify()->error('Oops', 'Something went wrong', 'warning shake animated');
        }

        $path = upload_path_images($path);

        // save the image
        $image = $imageTmp->fit($size['o'][0], $size['o'][1])->save($path . $filename);

        $image->fit($size['tn'][0], $size['tn'][1])->save($path . $filenameThumb);

        return $filename;
    }
28974
public function fileInfo($file,$path){
        if($file->isReadable()){
            $item = $this->fileDetails;
            $item["filename"] = $file->getFilename();
            $item["filetype"] = $file->getExtension();
            $item["lastmodified"] = $file->getMTime();
            $item["size"] = $file->getSize();
            if ($this->isImage($file)) {
                $thumb =  $this->firstThumb($file,$path);
                if($thumb){
                    $item['preview'] = $this->config['url'].$this->config['source'].'/'.$this->config['folder_thumb'].$path.$thumb;
                }
            }
            $item['previewfull'] = $this->config['url'].$this->config['source'].$path.$item["filename"];
            return $item;
        }else{
            return ;
        }
    }
221162
protected function handleUniqueFile($file)
    {
        $uploadedFile = null;

        //The current file was uploaded successfully?
        if (!$file['error']) {
            $uploadedFile = new UploadedFile(
                $file['tmp_name'],
                $file['name'],
                $file['type']
            );
        }

        return $uploadedFile;
    }
824436
public function init(\SplFileInfo $file, $extension = null)
    {
        $config = Grav::instance()['config'];

        // some extension logic
        if (empty($extension)) {
            $this->extension('.' . $file->getExtension());
        } else {
            $this->extension($extension);
        }

        // extract page language from page extension
        $language = trim(basename($this->extension(), 'md'), '.') ?: null;
        $this->language($language);

        $this->hide_home_route = $config->get('system.home.hide_in_urls', false);
        $this->home_route = $this->adjustRouteCase($config->get('system.home.alias'));
        $this->filePath($file->getPathname());
        $this->modified($file->getMTime());
        $this->id($this->modified() . md5($this->filePath()));
        $this->routable(true);
        $this->header();
        $this->date();
        $this->metadata();
        $this->url();
        $this->visible();
        $this->modularTwig(strpos($this->slug(), '_') === 0);
        $this->setPublishState();
        $this->published();
        $this->urlExtension();


        return $this;
    }
72351
public function upload($file)
    {
        if ($this->isSubmodule) {
            $file = $this->isSubmodule.'/'.$file;
        }

        $dir = explode('/', dirname($file));
        $path = '';
        $pathThatExists = null;
        $output = array();

        // Skip basedir or parent.
        if ($dir[0] != '.' and $dir[0] != '..') {
            // Iterate through directory pieces.
            for ($i = 0, $count = count($dir); $i < $count; $i++) {
                $path .= $dir[$i].'/';

                if (!isset($pathThatExists[$path])) {
                    $origin = $this->bridge->pwd();

                    // The directory doesn't exist.
                    if (! $this->bridge->exists($path)) {
                        // Attempt to create the directory.
                        $this->bridge->mkdir($path);
                        $output[] = "Created directoy '$path'.'";
                    }
                    // The directory exists.
                    else {
                        $this->bridge->cd($path);
                    }

                    $pathThatExists[$path] = true;
                    $this->bridge->cd($origin);
                }
            }
        }

        $uploaded = false;
        $attempts = 1;

        // Loop until $uploaded becomes a valid
        // resource.
        while (!$uploaded) {
            // Attempt to upload the file 10 times
            // and exit if it fails.
            if ($attempts == 10) {
                $output[] = "Tried to upload $file 10 times, and failed 10 times. Something is wrong, so I'm going to stop executing now.";
                return $output;
            }

            $data = file_get_contents($file);
            $uploaded = $this->bridge->put($data, $file);

            if (!$uploaded) {
                $attempts++;
            }
        }

        $output[] = "√ \033[0;37m{$file}\033[0m \033[0;32muploaded\033[0m";

        return $output;
    }
490643
public function setFileUpload(UploadedFile $file = null)
    {
        $propertyName = $this->getFileUploadPropertyName(__FUNCTION__);

        unset($this->fileUploads[$propertyName]);
        if ($file instanceof UploadedFile) {
            $this->fileUploads[$propertyName] = $file;
        }
    }
393100
public function make(UploadedFile $file, array $attributes = [])
    {
        $image = app('image')
            ->make($file->getPathname())
            ->resize(
                config('media.maxwidth', 2560),
                config('media.maxheight', null),
                function ($constraint) {
                    if (config('media.aspectratio', true)) {
                        $constraint->aspectRatio();
                    }
                    if (config('media.upsize', true)) {
                        $constraint->upsize();
                    }
                }
            )
            ->encode(null, config('media.compression', 80));

        return $this->save($file->getClientOriginalName(), $image, $attributes);
    }