限速
@param int $download 下载速度，为0则不限制，单位：字节
@param int $upload 上传速度，为0则不限制，单位：字节
@return static
559170
public function limitRate($download = 0, $upload = 0)
    {
        $this->downloadSpeed = $download;
        $this->uploadSpeed = $upload;
        return $this;
    }
1161230
function setCurrentImportOption( array $upload ) {

		try {
			$this->isValidZip( $upload['file'] );
		} catch ( \Exception $e ) {
			return false;
		}

		$option = [
			'file' => $upload['file'],
			'url' => $upload['url'] ?? null,
			'file_type' => $upload['type'],
			'type_of' => self::TYPE_OF,
			'chapters' => [],
		];

		$option['chapters'] = $this->getFuzzyChapterTitles();

		return update_option( 'pressbooks_current_import', $option );
	}
309530
public function createUmbrellaFile(UploadedFile $file, $upload = false)
    {
        $umbrellaFile = new UmbrellaFile();
        $umbrellaFile->name = $file->getClientOriginalName();
        $umbrellaFile->md5 = md5_file($file->getRealPath());
        $umbrellaFile->mimeType = $file->getMimeType();
        $umbrellaFile->size = $file->getSize();

        if ($upload) {
            $umbrellaFile->path = $this->upload($file);
        } else {
            $umbrellaFile->file = $file;
        }
        return $umbrellaFile;
    }
1307925
public function streamDownload($callback, $name = null, array $headers = [], $disposition = 'attachment')
    {
        $response = new StreamedResponse($callback, 200, $headers);

        if (! is_null($name)) {
            $response->headers->set('Content-Disposition', $response->headers->makeDisposition(
                $disposition,
                $name,
                $this->fallbackName($name)
            ));
        }

        return $response;
    }
188630
public function file(string $file, string $name = null, bool $download = true): ResponseInterface
    {
        if (!\is_file($file)) {
            throw new \LogicException("File '$file' doesn't exist.");
        }

        $extension = \substr($file, \strrpos($file, '.') + 1);
        $this->header->set('Content-Type',
            MimeType::getMimeType($extension) ?? 'application/octet-stream'
        );

        $disposition = $download ? Header::DISPOSITION_ATTACHMENT : Header::DISPOSITION_INLINE;
        $this->header->set('Content-Disposition',
            $this->header->makeDisposition($disposition, $name, \basename($file))
        );

        $size = $length = \filesize($file);

        $this->header->set('Accept-Ranges', 'bytes');
        if (\preg_match('#^bytes=(\d*)-(\d*)\z#', $this->request->header('Range'), $matches)) {
            list(, $start, $end) = $matches;

            if ($start === '') {
                $start = \max(0, $size - $end);
                $end = $size - 1;
            } elseif ($end === '' || $end > $size - 1) {
                $end = $size - 1;
            }

            if ($end < $start) {
                return $this->empty(416); // requested range not satisfiable
            }

            $this->setStatus(206);
            $this->header->set('Content-Range', 'bytes ' . $start . '-' . $end . '/' . $size);
            $length = $end - $start + 1;
        } else {
            $this->header->set('Content-Range', 'bytes 0-' . ($size - 1) . '/' . $size);
        }

        $this->header->set('Content-Length', $length);

        $this->app->emitter(
            $this->emitter ?? Emitter\SapiStream::class
        );

        return $this->response(
            Factory::streamFromFile($file, 'rb')
        );
    }
1255894
public function streamFile($container, $path, $download = false)
    {
        $params = ($download) ? ['disposition' => 'attachment'] : [];
        $this->streamBlob($container, $path, $params);
    }
572790
public function push($deploy)
    {
        // Compare local revision to the remote one, to
        // build files to upload and delete.
        $message = $deploy->compare();
        print $message;
        print "\n+ --------------- + --------------- +";

        $dirty = false;

        $filesToUpload = $deploy->getFilesToUpload();
        $filesToDelete = $deploy->getFilesToDelete();

        if ($filesToUpload) {
            foreach ($filesToUpload as $file) {
                // On list mode, just print the file.
                if ($this->mode == self::MODE_LIST) {
                    print "\n√ \033[0;37m{$file}\033[0m \033[0;32mwill be uploaded\033[0m";
                    continue;
                }

                $output = $deploy->upload($file);

                // An upload procedure may have more than one
                // output message (uploaded file, created dir, etc).
                foreach ($output as $message) {
                    print "\n" . $message;
                }
            }
        }

        if ($filesToDelete) {
            foreach ($filesToDelete as $file) {
                // On list mode, just print the file.
                if ($this->mode == self::MODE_LIST) {
                    print "\n× \033[0;37m{$file}\033[0m \033[0;31mwill be removed\033[0m";
                    continue;
                }

                print "\n" . $deploy->delete($file);
            }
        }

        // Files were uploaded or deleted, so mark
        // it as dirty.
        if ($filesToUpload or $filesToDelete) {
            $dirty = true;
        }

        return $dirty;
    }
323626
public function downloadAction() {
        $ini = Zend_Registry::get('config');
        $downloadType = $this->getRequest()->getParam('downloadType') ?: Garp_File::TYPE_DOCUMENTS;
        $uploadOrStatic = $this->getRequest()->getParam('uploadOrStatic') ?: 'upload';
        $file = $this->getRequest()->getParam('file');

        if (!$file) {
            throw new Zend_Controller_Action_Exception('Geen bestandsnaam opgegeven.', 404);
        }

        try {
            $fileHandler = new Garp_File($downloadType, $uploadOrStatic);
            $url = $fileHandler->getUrl($file);
            $this->_downloadFile($url);
        } catch (Garp_File_Exception_InvalidType $e) {
            // Just throw a 404, since the error is basically just a wrong URL.
            throw new Zend_Controller_Action_Exception($e->getMessage(), 404);
        }
    }
1019637
public static function createFromUploadedFile(UploadedFile $file = null)
    {
        if (!$file instanceof UploadedFile) {
            return;
        }

        $instance = new static();

        self::$generic_file->moveUploadedFile(new File($file,
            $file->getClientOriginalName()), null, $instance);

        return $instance;
    }
1028935
public function removeFromTemp(Upload $file)
    {
        return $this->getTempFilesystem($file->getPath())->delete($file->getBasename());
    }
992635
public function continueUpload($uploadId,$fileOffset,$content)
    {
        $returnValue = new ClientResult();
        $qry = new InvokePostMethodQuery($this->getResourcePath(),
            "ContinueUpload",
            array('uploadId' => $uploadId->toString(),'fileOffset' => $fileOffset),
            $content);
        $this->getContext()->addQuery($qry,$returnValue);
        return $returnValue;
    }
1250375
public static function maxUpload ($default = null)
		{
			$bytes = self::maxBytesUpload();

			return ( $bytes == null ) ? $default : self::size($bytes);
		}
647764
public function addUploadedFile(UploadedFileInterface $upload, string $field = null, array $crop = null): string
    {
        $tmp_dir = $this->getTmpDir();
        $tmp_name = Utils::generateRandomString(12);
        $name = $upload->getClientFilename();

        // Prepare upload data for later save
        $data = [
            'name' => $name,
            'type' => $upload->getClientMediaType(),
            'size' => $upload->getSize(),
            'tmp_name' => $tmp_name
        ];

        Folder::create($tmp_dir);
        $upload->moveTo("{$tmp_dir}/{$tmp_name}");

        $this->addFileInternal($field, $name, $data, $crop);

        return $name;
    }
1317907
public function uploadWithToken($uploadToken, $filePath, $key = null){
        $uploadMgr = new UploadManager();
        list($ret, $err) = $uploadMgr->putFile($uploadToken, $key, $filePath);
        if($err){
            return $this->error($err->message(), ['errorCode'=>$err->code()]);
        }
        return $this->success('操作成功', $ret);
    }
176273
public function setMaxFilesize($bytes)
    {
        // Make compatible with PHP version both before and after 5.5.0. PHP 5.5.0 added the cURL resource as the first
        // argument to the CURLOPT_PROGRESSFUNCTION callback.
        $gte_v550 = version_compare(PHP_VERSION, '5.5.0') >= 0;
        if ($gte_v550) {
            $callback = function ($resource, $download_size, $downloaded, $upload_size, $uploaded) use ($bytes) {
                // Abort the transfer when $downloaded bytes exceeds maximum $bytes by returning a non-zero value.
                return $downloaded > $bytes ? 1 : 0;
            };
        } else {
            $callback = function ($download_size, $downloaded, $upload_size, $uploaded) use ($bytes) {
                return $downloaded > $bytes ? 1 : 0;
            };
        }

        $this->progress($callback);
    }
117227
protected function movePhpUploadTmpFiles(array $upload)
    {
        $asArray     = is_array($upload['tmp_name']);
        $tmpFiles    = (array) $upload['tmp_name'];
        $filenames   = (array) $upload['name'];
        $files       = array();
        
        foreach ($tmpFiles as $key => $tmpFile) {
            
            if (!is_uploaded_file($tmpFile)) {
                throw new Exception\UploadException(
                    'File is not an uploaded file', array(), 10110);
            }
            
            $filename   = $filenames[$key];
            $tmpDir     = $this->getTempDir();
            $targetDir  = $tmpDir . '/valu_so_upload_' . md5(basename($tmpFile) . microtime(true));
            $file       = $targetDir . DIRECTORY_SEPARATOR . $filename;
            
            if (!file_exists($targetDir) && mkdir($targetDir)) {
                move_uploaded_file($tmpFile, $file);
                
                $files[] = realpath($file);
            }
        }

        return $files;
    }
1010620
public function handleUpload(&$uploader)
    {
        // store uploader
        $this->uploader =& $uploader;
        //store input
        $this->setInput();
        // tell uploader which field is uploaded
        $this->uploader->setField($this->field);
        // make temporary file
        $this->uploader->setDestination(sys_get_temp_dir());
        // loop validation rules
        foreach($this->validations as $validation) {
            $options = isset($validation['options']) ? $validation['options'] : null;
            $message = isset($validation['message']) ? $validation['message'] : null;
            // set rule
            $this->uploader->addValidationRule($validation['type'], $options, $message);
        }
        // upload
        if(!$this->uploader->process()) {
            // failure
            return false;
        }
        // loop field outputs
        $temporaryFile = sprintf('%s/%s', sys_get_temp_dir(), $this->uploader->getUploadedFileInfo()['name']);
        foreach($this->outputs as $outputName => $output) {
            $outputPath = $output->getDestination() .  $this->uploader->getUploadedFileInfo()['name'];
            if(is_file($outputPath)){
                $outputPath = sprintf('%s%s_%s', $output->getDestination(), time(),  $this->uploader->getUploadedFileInfo()['name']);
            }
            copy($temporaryFile, $outputPath);
            $this->outputsFiles[$outputName] = [
                'name' => $this->uploader->getUploadedFileInfo()['name'],
                'path' => $outputPath
            ];
        }
        // delete temporary file
        unlink($temporaryFile);
        // close upload
        $this->uploader->close();
        return true;
    }