A class to help with creating downloads for files in PHP.
If you can use direct downloads, you should just use them. This class is for providing downloads of files out of PHP, for example if you want to provide a download to a temporarily created file.
The examples assume, that you have included the namespace:
use Apfelbox\FileDownload\FileDownload;
$fileDownload = FileDownload::createFromFilePath("/path/to/file.pdf");
$fileDownload->sendDownload("download.pdf");
$file = /* your file, somewhere opened with fopen() or tmpfile(), etc.. */;
$fileDownload = new FileDownload($file);
$fileDownload->sendDownload("download.pdf");
$content = "This is the content of the file:";
$fileDownload = FileDownload::createFromString($content);
$fileDownload->sendDownload("download.txt");
For example, you can create downloads for PDF files, generated by Zend (or any other library):
$pdf = new Zend_Pdf();
$page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
$pdf->pages[] = $page;
/* draw content in the pdf ... */
$fileDownload = FileDownload::createFromString($pdf->render());
$fileDownload->sendDownload("download.pdf");