@@ -3,14 +3,22 @@ layout: page
3
3
title : User Input
4
4
parent_title : Real life examples
5
5
permalink : /real-life-examples/user-input.html
6
- modification_time : 2015-08-05T12:00 :28+00 :00
6
+ modification_time : 2025-05-13T16:54 :28+02 :00
7
7
---
8
8
9
9
These scripts allow you to present a form to the user, who can enter text and upload an image; these are displayed first
10
10
in the browser, with the option to create a PDF file from the output. These scripts should only be considered the basis
11
11
of a full script and will need adapting considerably. In particular, note that the uploaded image files may need to be
12
12
deleted at some point.
13
13
14
+ <div class =" alert alert-danger " role =" alert " markdown =" 1 " >
15
+ ** Warning:** All user input passed to mPDF should be sanitized properly.
16
+
17
+ Examples below serve only as a preview what can be done and must not be used as such.
18
+
19
+ Also, for purposes of these examples, note that the file upload mechanics were simplified and do not solve data validation and/or verification.
20
+ </div >
21
+
14
22
` example_userinput.php `
15
23
16
24
``` html
@@ -49,15 +57,16 @@ if (($_FILES["file"]["type"] == "image/gif" || $_FILES["file"]["type"] == "image
49
57
50
58
$html = '<html >
51
59
<body >
52
- <div >' . $_POST['text'] . '</div >
53
- <img src =" ' ." .. /tmp /" . $_FILES[" file " ][" name " ] . '" />
60
+ <div >' . htmlspecialchars($_POST['text']) . '</div >
61
+
62
+ <img src =" ' ." .. /tmp /" . htmlspecialchars($_FILES[" file " ][" name " ]) . '" />
54
63
55
64
<form action =" example_userinput3.php" method =" post" enctype =" multipart/form-data" >
56
65
<textarea style =" display :none " name =" text" id =" text" >'
57
- . $_POST['text']
66
+ . htmlspecialchars( $_POST['text'])
58
67
. '</textarea >
59
68
<input type =" hidden" name =" filename" id =" filename"
60
- value =" '. $_FILES[" file " ][" name " ].'" />
69
+ value =" '. htmlspecialchars( $_FILES[" file " ][" name " ]) .'" />
61
70
<input type =" submit" name =" submit" value =" Create PDF file" />
62
71
</form >
63
72
</body >
@@ -77,8 +86,8 @@ $mpdf = new \Mpdf\Mpdf();
77
86
78
87
$html ='<html >
79
88
<body >
80
- <div >'. $_POST['text'].'</div >
81
- <img src =" ' . " .. /tmp /" . $_POST['filename'] . '" />
89
+ <div >' . htmlspecialchars( $_POST['text']) .'</div >
90
+ <img src =" ' . " .. /tmp /" . htmlspecialchars( $_POST['filename']) . '" />
82
91
</body >
83
92
</html >';
84
93
0 commit comments