nzo/file-downloader-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nzo/file-downloader-bundle

Composer 安装命令:

composer require nzo/file-downloader-bundle

包简介

The NzoFileDownloaderBundle is a Symfony Bundle used to Download all types of files from servers and Web applications safely and with ease. You can also read/show the file content in the Web Browser.

README 文档

README

tests Total Downloads Latest Stable Version

The NzoFileDownloaderBundle is a Symfony Bundle used to Download all types of files from servers and Web application projects safely and with ease. You can also read/show the file content in the Web Browser.

Features include:

  • This version of the bundle is compatible with Symfony >= v4.4
  • Read/Show the file content in the Web Browser.
  • Download all types of files from the Symfony public folder or from a custom path.
  • Change the name of the file when downloading.
  • Download Files From Url
  • Get Files Extension From Url

Installation

Through Composer:

$ composer require nzo/file-downloader-bundle

Register the bundle in config/bundles.php (without Flex)

// config/bundles.php

return [
    // ...
    Nzo\FileDownloaderBundle\NzoFileDownloaderBundle::class => ['all' => true],
];

Usage

Read / Show the file content in the Web Browser:

use Nzo\FileDownloaderBundle\FileDownloader\FileDownloader;

class MyController extends AbstractController
{
    private $fileDownloader;

    public function __construct(FileDownloader $fileDownloader)
    {
        $this->fileDownloader = $fileDownloader;
        
        // without autowiring use: $this->get('nzo_file_downloader')
    }

// In this examples the "myfile.pdf" file exist in "public/myfolder/myfile.pdf".

     public function readFilesFromPublicFolder()
     {
          return $this->fileDownloader->readFile('myfolder/myfile.pdf');
     }

     // Absolute PATH:

     public function readFilesFromAbsolutePath()
      {
           return $this->fileDownloader->readFileFromAbsolutePath('/home/user/myfile.pdf');
      }
}    

Download the Files:

     public function downloadFileFromPublicFolder()
     {
          return $this->fileDownloader->downloadFile('myfolder/myfile.pdf');

        # change the name of the file when downloading:

          return $this->fileDownloader->downloadFile('myfolder/myfile.pdf', 'newName.pdf');
     }


     // Absolute PATH:

     public function downloadFilesFromAbsolutePath()
      {
           return $this->fileDownloader->downloadFileFromAbsolutePath('/home/user/myfile.pdf');

         # change the name of the file when downloading:

           return $this->fileDownloader->downloadFileFromAbsolutePath('/home/user/myfile.pdf', 'newName.pdf');
      }
}    
Download Files from URL:
    public function downloadFileFromUrl(string $url, string $pathWhereToDownloadTheFile, ?string $customUserAgent = null)
    {
        $headers = ['Authorization: Basic auth'];
        
        $response =  $this->fileDownloader->downloadFileFromUrl($url, $pathWhereToDownloadTheFile, $headers, /** You can pass an optional custom User-Agent as third argument ($customUserAgent) */);
    
        if (false !== $response) {
            // File downloaded successfully !
        } else {
            // Error occurred ! 
        }   
    }
Get Files Extension From URL:
public function getFileExtensionFromUrl(string $url)
{
    $fileExtension = $this->fileDownloader->getFileExtensionFromUrl($url);

    if (null === $fileExtension) {
        // Error occurred ! 
    }
}
Download a Symfony StreamedResponse:
    use Symfony\Component\HttpFoundation\StreamedResponse;

    // ...

    public function downloadStreamedResponse()
    {
        $streamedResponse = new StreamedResponse();
        // ...

        $fileName = 'someFileName.csv';

        return $this->fileDownloader->downloadStreamedResponse($streamedResponse, $fileName);
    }

License

This bundle is under the MIT license. See the complete license in the bundle:

See Resources/doc/LICENSE

统计信息

  • 总下载量: 19.94k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 3
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-03-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固