GithubHelp home page GithubHelp logo

vitqst / filedownloader Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jkuchar/filedownloader

0.0 2.0 0.0 528 KB

Allows you to send files to browser from Presenter. (also can be used without Nette) Allows you to log and restrict access to these files. There is also support for partial downloads and files over 4GB!

Home Page: http://addons.nette.org/jkuchar/filedownloader

License: Other

PHP 100.00%

filedownloader's Introduction

File Downloader

Code Climate

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.

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){
	/* ... */
}
Callback name Description
BeforeDownloaderStarts Before downloader starts
BeforeOutputStarts Before output to browser starts (last chance to modify HTTP headers)
StatusChange When file download status changes (when block of file is sent or every second if there is no speed limit)
Complete When file download is finished
Abort When file download is aborted (user clicks cancel)
ConnectionLost When connection is lost (for whatever reason)
TransferContinue When paused transfer continues (this is start event for partial downloads)
NewTransferStart When new transfer from beginning starts (this is start event for downloads from beginning)

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.