Upload file to the upload dir, returns the newly uploaded file

@param  array  $file
@param  string $to
@return mixed
490473
public function upload($file, $to = null)
    {
        if ($this->test($file)) {
            if (null === $to) {
                $to = $file['name'];
            }
            if (!$this->overwrite) {
                $to = $this->checkFilename($to);
            }

            $this->uploadedFile = $to;
            $to = $this->uploadDir . DIRECTORY_SEPARATOR . $to;

            // Move the uploaded file, creating a file object with it.
            if (move_uploaded_file($file['tmp_name'], $to)) {
                return $this->uploadedFile;
            } else {
                $this->error = self::UPLOAD_ERR_UNEXPECTED;
                return false;
            }
        } else {
            return false;
        }

    }
812854
protected function publishFile($from, $to)
    {
        if ($this->files->exists($to) && ! $this->option('force')) {
            return;
        }

        $directory = dirname($to);

        if (! $this->files->isDirectory($directory)) {
            $this->files->makeDirectory($directory, 0755, true);
        }

        $this->files->copy($from, $to);

        $this->status($from, $to, 'File');
    }
345014
protected function onReleaseReady($from, $to)
    {
        $this->explainer->comment(sprintf('Uploading files from %s to %s', $from, $to));

        // Only gather files from existing folders (for pretend mode)
        $folders = array_filter([$from], 'is_dir');
        if (!$folders) {
            return true;
        }

        $files = (new Finder())->in($folders)->exclude(['.git']);
        $format = $this->explainer->getProgressBarFormat(
            '%current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s%'.PHP_EOL.
            '%message%'
        );

        // Create progress bar
        $progress = $this->command->createProgressBar(iterator_count($files));
        $progress->setFormat($format);
        $progress->start();

        foreach ($files as $file) {
            $origin = str_replace($from, null, $file->getPathname());
            $path = $to.DS.str_replace($from, null, $file->getPathname());
            $progress->setMessage(
                dirname($origin).DS.
                '<info>'.basename($origin).'</info>'
            );

            if ($file->isDir()) {
                $this->createFolder($path);
            } else {
                $this->put($path, $file->getContents());
            }

            $progress->advance();
        }

        $progress->finish();

        return true;
    }
1147268
public function handleSingleFile($file)
    {
        if (!$file instanceof UploadedFile) {
            throw new \Exception("Dados inválidos para upload");
        }

        $document = $this->createDocument($file);

        $this->processBeforeSave($document);

        $disk = Storage::disk()->getDriver();
        $disk->put($document->filePath, fopen($file, 'r+'), [
            'visibility' => 'public',
            'ContentType' => $document->mimeType
        ]);

        $document->url = config('filesystems.default') == 'public' ? asset('images/' . $document->filePath) : Storage::url($document->filePath);
        $document->save();

        $this->addFileToList($document);

        return $document;
    }
1022183
public static function fileToArray($file)
    {
        if (! is_file($file) && ! filter_var($file, FILTER_VALIDATE_URL)) {
            self::arrayToFile([], $file);
        }

        $json = @file_get_contents($file);
        $array = json_decode($json, true);
        $lastError = JsonLastError::check();

        return $array === null || !is_null($lastError) ? false : $array;
    }
681720
protected function uploadZipToTemp($file)
    {
        if (!file_exists($file)) {
            throw new Exception(t('Could not transfer to temp directory - file not found.'));
        } else {
            $dir = time();
            copy($file, $this->f->getTemporaryDirectory() . '/'. $dir . '.zip');

            return $dir;
        }
    }
1208441
private function convertFile(array $file)
    {
        if (!isset($file['name']) || !isset($file['type']) || !isset($file['tmp_name']) || !isset($file['error']) || !isset($file['size'])) {
            return null;
        }

        if (is_array($file['error'])) {
            $result = [];
            foreach ($file['error'] as $key => $error) {
                $result[$key] = $this->convertFile([
                    'name'     => $file['name'][$key],
                    'type'     => $file['type'][$key],
                    'tmp_name' => $file['tmp_name'][$key],
                    'error'    => $file['error'][$key],
                    'size'     => $file['size'][$key],
                ]);
            }
        }
        else {
            $result = new \Core\Services\UploadedFile($file['tmp_name'], $file['name'], $file['error']);
        }

        return $result;
    }
257670
public function universalizeUpload($file)
    {
        if ((is_string($file) && is_file($file)) || $file instanceof File) {
            return $file;
        }

        return $this->getUploadedFlyFile($file);
    }
40292
public function upload(File $file, UploadedFile $upload, $contents)
    {
        $this->generateFilename($file);

        $method = 'write';

        if (is_resource($contents) && get_resource_type($contents) == 'stream') {
            $method = 'writeStream';
        }

        $meta = $this->adapter->{$method}($file->path, $contents, new Config());

        if (!$meta) {
            return false;
        }

        $this->meta = $meta;

        $this->generateUrl($file);

        return $file;
    }
1060764
public function uploadQiniu($file)
    {
        $info = [
            'success' => 1,
            'message' => '上传成功',
            'url' => '',
        ];

        $filename = $this->getFilename($file);

        $auth = new Auth($this->qiniuAccessKey, $this->qiniuSecretKey);
        $token = $auth->uploadToken($this->qiniuBucket);

        $upManager = new UploadManager();

        list($code, $error) = $upManager->putFile($token, $filename, $file);

        if ($error) {
            $info['success'] = 0;
            $info['message'] = $error->message();
            return $info;
        }

        $info['url'] = $this->qiniuDomain . DIRECTORY_SEPARATOR . $filename;
        return $info;
    }
837409
public function move($from, $to)
    {
        event(new Events\FileMoving($from, $to));
        $moved = $this->disk()->move($from, $to);
        event(new Events\FileMoved($from, $to, $moved));

        return $moved;
    }
1264292
public function moveTo($to, $filename = null)
    {
        if (!isset($this->file['tmp_name'])) {
            return false;
        }

        if (!is_null($filename)) {
            $filename = $this->getHashName();
        }

        if (!is_dir($to)) {
            @mkdir($to, 0777, true);
        }

        $resolve = rtrim($to, '/').'/'.$filename;

        return (bool) move_uploaded_file($this->file['tmp_name'], $resolve);
    }
829872
private function moveToFile(array $file, $targetFile)
    {
        $dir = \dirname($targetFile);

        if (!$this->_makeDir($dir)) {
            $this->error = "目录创建失败或者不可写. DIR: [$dir]";

            return false;
        }

        if (!move_uploaded_file($file['tmp_name'], $targetFile)) {
            $this->error = '移动上传文件失败！';

            return false;
        }

        $file['newFile'] = $targetFile;

        return $file;
    }
19961
public function copyTo(FileNode $from, FileNode $to)
    {
        $mountManager = new MountManager([
            'from' => $from->getFilesystem(),
            'to'   => $to->getFilesystem(),
        ]);

        $this->log(LogLevel::INFO, "Copying file from: '{from}', to: '{to}'", [
            'from' => $from,
            'to'   => $to,
        ]);
        if (!$mountManager->copy('from://' . $from->getPath(), 'to://' . $to->getPath())) {
            throw new TransferFailedException($from, $to);
        }

        return $to;
    }
681335
protected function publishItem($from, $to)
    {
        if ($this->files->isFile($from)) {
            return $this->publishFile($from, $to);
        } elseif ($this->files->isDirectory($from)) {
            return $this->publishDirectory($from, $to);
        }

        $this->error("Can't locate path: <{$from}>");
    }
575702
public function copyFile( $from, $to )
	{
		$this->connection->checkConnection();
		$temp	= uniqid( time() ).".temp";
		$reader	= new Net_FTP_Reader( $this->connection );
		$reader->setPath( $this->getPath() );
		if( !$reader->getFile( $from, $temp ) )
			throw new RuntimeException( 'File "'.$from.'" could not be received.' );
		if( !$this->putFile( $temp, $to ) )
		{
			unlink( $temp );
			throw new RuntimeException( 'File "'.$from.'" could not be stored.' );
		}
		unlink( $temp );
		return TRUE;
	}
668846
public function upload(File $file, UploadedFile $upload, $contents)
    {
        $response = $this->api->post('upload', [
            'json' => [
                'type'  => 'base64',
                'image' => base64_encode($contents),
            ],
        ]);

        // successful upload, let's get the generated URL
        if ($response->getStatusCode() == 200) {
            $meta = Arr::get(json_decode($response->getBody(), true), 'data', []);

            $link = Arr::get($meta, 'link');

            $file->url = preg_replace('/^https?:/', null, $link);
            $file->remote_id = Arr::get($meta, 'id');
        }

        if ($response->getStatusCode() != 200 || empty($file->url)) {
            return false;
        }

        return $file;
    }