Skip to content
This repository was archived by the owner on Sep 30, 2022. It is now read-only.

Commit 7521b31

Browse files
committed
Created project description
1 parent 561d05d commit 7521b31

File tree

1 file changed

+60
-2
lines changed

1 file changed

+60
-2
lines changed

README.md

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,62 @@
1-
PHP-File-Download
1+
PHP File Download
22
=================
33

4-
A class to help with creating download for files in PHP
4+
A class to help with creating downloads for files in PHP.
5+
6+
7+
Hint
8+
----
9+
10+
If you can use direct downloads, you should just use them.
11+
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.
12+
13+
14+
Usage
15+
=====
16+
17+
Create a download for a file on your file system
18+
---
19+
```
20+
<?php
21+
22+
$fileDownload = FileDownloader::createFromFilePath("/path/to/file.pdf");
23+
$fileDownload->sendDownload("download.pdf");
24+
```
25+
26+
27+
Create a download for a file via file pointer
28+
---
29+
```
30+
<?php
31+
32+
$file = /* your file, somewhere opened with fopen() or tmpfile(), etc.. */;
33+
$fileDownload = new FileDownloader($file);
34+
$fileDownload->sendDownload("download.pdf");
35+
```
36+
37+
38+
Create a download for a file via the content
39+
---
40+
```
41+
<?php
42+
43+
$content = "This is the content of the file:";
44+
$fileDownload = FileDownloader::createFromString($content);
45+
$fileDownload->sendDownload("download.txt");
46+
```
47+
48+
49+
For example, you can create downloads for PDF files, generated by Zend (or any other library):
50+
51+
```
52+
<?php
53+
54+
$pdf = new Zend_Pdf();
55+
$page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
56+
$pdf->pages[] = $page;
57+
58+
/* draw content in the pdf ... */
59+
60+
$fileDownload = FileDownloader::createFromString($pdf->render());
61+
$fileDownload->sendDownload("download.pdf");
62+
```

0 commit comments

Comments
 (0)