This repository was archived by the owner on Sep 30, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +60
-2
lines changed Expand file tree Collapse file tree 1 file changed +60
-2
lines changed Original file line number Diff line number Diff line change 1
- PHP- File- Download
1
+ PHP File Download
2
2
=================
3
3
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
+ ```
You can’t perform that action at this time.
0 commit comments