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