apfelbox / php-file-download
此包已被废弃,不再维护。未建议替代包。
一个用于帮助在PHP中创建文件下载的库
v2.1
2014-02-10 17:12 UTC
Requires
- php: >=5.3
- skyzyx/mimetypes: ~1.1
This package is not auto-updated.
Last update: 2022-10-01 05:43:35 UTC
README
一个用于帮助在PHP中创建文件下载的类。
提示
如果您可以使用直接下载,您应该直接使用。此类用于提供PHP之外文件的下载,例如,如果您想提供对临时创建的文件的下载。
用法
以下示例假设您已经包含了命名空间
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");
例如,您可以创建由Zend(或任何其他库)生成的PDF文件的下载
$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");