karelwintersky/arris.php-file-download
最新稳定版本:2.1.0
Composer 安装命令:
composer require karelwintersky/arris.php-file-download
包简介
A library to help with creating downloads for files in PHP
README 文档
README
A class to help with creating downloads for files in PHP.
Tip
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.
Usage
The examples assume, that you have included the namespace:
use Arris\Toolkit\FileDownload;
Create a download for a file on your file system
$fileDownload = FileDownload::createFromFilePath("/path/to/file.pdf"); $fileDownload->sendDownload("download.pdf");
Create a download for a file via file pointer
$file = /* your file, somewhere opened with fopen() or tmpfile(), etc.. */; $fileDownload = new FileDownload($file); $fileDownload->sendDownload("download.pdf");
Create a download for a file via content
$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");
NB
Если в методе sendDownload() опустить имя файла - оно будет равно имени файла, которое передали конструктору.
Есть нюанс: если файл создается из строки: createFromString() - отсутствие аргумента в sendDownload() предписывает
скачать файл с пустым именем. Последствия неизвестны.
统计信息
- 总下载量: 471
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-10-26