2017 © Pedro Peláez
 

symfony-bundle 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.

image

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.

  • Monday, May 29, 2017
  • by NAYZO
  • Repository
  • 4 Watchers
  • 5 Stars
  • 1,283 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 8 Versions
  • 8 % Grown

The README.md

NzoFileDownloaderBundle

tests Total Downloads Latest Stable Version, (*1)

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., (*2)

Features include:, (*3)

  • 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:

``` bash $ composer require nzo/file-downloader-bundle, (*4)


#### Register the bundle in config/bundles.php (without Flex) ``` php // 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:, (*5)

See Resources/doc/LICENSE, (*6)

The Versions

29/05 2017

dev-master

9999999-dev

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.

  Sources   Download

MIT

The Requires

 

read file bundle symfony upload show browser download downloader

25/11 2016

2.2

2.2.0.0

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.

  Sources   Download

MIT

The Requires

 

read file bundle symfony upload show browser download downloader

21/09 2016

2.1

2.1.0.0

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.

  Sources   Download

MIT

The Requires

 

read file bundle symfony upload show browser download downloader

27/04 2016

2.0

2.0.0.0

The NzoFileDownloaderBundle is a Symfony2 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.

  Sources   Download

MIT

The Requires

 

read file bundle symfony upload show browser download downloader

27/04 2016

1.3

1.3.0.0

The NzoFileDownloaderBundle is a Symfony2 Bundle used to Download all types of files from servers and Web applications safely and with ease

  Sources   Download

MIT

The Requires

 

file bundle symfony upload download downloader

21/12 2015

1.2

1.2.0.0

The NzoFileDownloaderBundle is a Symfony2 Bundle used to Download all types of files from servers and Web applications safely and with ease

  Sources   Download

MIT

The Requires

 

file bundle symfony upload download downloader

18/04 2015

1.1

1.1.0.0

The NzoFileDownloaderBundle is a Symfony2 Bundle used to Download all types of files from servers and Web applications safely and with ease

  Sources   Download

MIT

The Requires

 

file bundle symfony upload download downloader

31/01 2015

1.0

1.0.0.0

The NzoFileDownloaderBundle is a Symfony2 Bundle used to Download all types of files from servers and Web applications safely and with ease

  Sources   Download

MIT

The Requires

 

file bundle symfony upload download downloader