jkuchar / filedownloader
Addon makes controlled downloads of files peace of cake. It supports client reconnections, segmented downloading, files over 4GB, automatic mime-type detection and special characters in file names. If you need to control download speed you are on the right site.
Installs: 30 611
Dependents: 1
Suggesters: 0
Security: 0
Stars: 28
Watchers: 4
Forks: 10
Open Issues: 5
Requires
- php: >= 5.3.0
- jkuchar/bigfiletools: >=1.1.0 <=2.0
- nette/application: ~2.4
- nette/deprecated: ^2.4
This package is auto-updated.
Last update: 2024-10-23 19:56:15 UTC
README
looking for new maintainer(s) Please use Nette\Application\Responses\FileResponse instead. Or hi-speed solution X-Accel/NGINX or X-Sendfile/Apache.
Addon makes controlled downloads of files peace of cake. It supports client reconnections, segmented downloading, files over 4GB, automatic mime-type detection and special characters in file names. If you need to control download speed you are on the right site.
- License: New BSD License
- Discussion
- Demo
Installation
Install this addon just by calling:
composer require jkuchar/filedownloader
Or to install example, continue to example repository. (one command set-up)
Basic usage: Just want to download file
Import FileDownloader from it's namespace
use FileDownloader\FileDownload;
And use
$filedownload = new FileDownload; $filedownload->sourceFile = "source.txt"; $filedownload->download(); // or the same thing using fluent-interface FileDownload::getInstance() ->setSourceFile("source.txt") ->download();
Advanced usage: combination of advanced features
$filedownload = new FileDownload(); $filedownload->sourceFile = "source.txt"; // apply speed limit (in this case in bytes per second) $filedownload->speedLimit = 5 * FDTools::BYTE; // set filename that will be seen by user $filedownload->transferFileName = "test.txt"; // set mime-type manually (you normally do not need to so this!) $filedownload->mimeType = "application/pdf"; // show this file directly in browser (do not download it) $filedownload->contentDisposition = FileDownload::CONTENT_DISPOSITION_INLINE; $filedownload->download();
The same thing using fluent-interface:
FileDownload::getInstance() ->setSourceFile("source.txt") // Nastavíme rychlost odesílání v bytech ->setSpeedLimit(5*FDTools::BYTE) ->setTransferFileName("test.txt") ->setMimeType("application/pdf") ->setContentDisposition( FileDownload::CONTENT_DISPOSITION_INLINE ) ->download();
Callbacks
When... ...download is cancelled ...download failed ...download succeded etc.
$filedownload->onAbort[] = "onAbortHandlerFunction"; // here is everything callable accepted // fluent-interface FileDownload::getInstance()->addAbortCallback("onAbortHandlerFunction") // Callback parameters are always the same function onAbort(FileDownload $download,IDownloader $downloader){ /* ... */ }
In repository there is example form that prints on screen all called callbacks.
Technical requirements
There are two downloaders AdvancedDownloader requires to set infinite time limit (tries to do so automatically). As fallback there is NativePHPDownloader available, this downloader requires as much memory as is file size on some PHP installtions. (php bug: if you've found solution, please let me know)
Callbacks, speed controlling and support for big files is only for AdvancedFileDownloader!
Support for huge files (over 4 GB)
- This is realized through cURL extension so please do not forget to enable it. Addon will work also without CURL but very inefficiently.
- Support for >4GB files also requires to add BigFileTools into your libraries (do that using composer)