PHP code example of jkuchar / filedownloader

1. Go to this page and download the library: Download jkuchar/filedownloader library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jkuchar / filedownloader example snippets


use FileDownloader\FileDownload;

$filedownload = new FileDownload;
$filedownload->sourceFile = "source.txt";
$filedownload->download();

// or the same thing using fluent-interface
FileDownload::getInstance()
	->setSourceFile("source.txt")
	->download();


$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();


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();


$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){
	/* ... */
}