PHP code example of apfelbox / php-file-download

1. Go to this page and download the library: Download apfelbox/php-file-download 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/ */

    

apfelbox / php-file-download example snippets


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

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