1 | <?php |
||
28 | class WebRequestUpload { |
||
29 | protected $request; |
||
30 | protected $doesExist; |
||
31 | protected $fileInfo; |
||
32 | |||
33 | /** |
||
34 | * Constructor. Should only be called by WebRequest |
||
35 | * |
||
36 | * @param WebRequest $request The associated request |
||
37 | * @param string $key Key in $_FILES array (name of form field) |
||
38 | */ |
||
39 | public function __construct( $request, $key ) { |
||
46 | |||
47 | /** |
||
48 | * Return whether a file with this name was uploaded. |
||
49 | * |
||
50 | * @return bool |
||
51 | */ |
||
52 | public function exists() { |
||
55 | |||
56 | /** |
||
57 | * Return the original filename of the uploaded file |
||
58 | * |
||
59 | * @return string|null Filename or null if non-existent |
||
60 | */ |
||
61 | public function getName() { |
||
76 | |||
77 | /** |
||
78 | * Return the file size of the uploaded file |
||
79 | * |
||
80 | * @return int File size or zero if non-existent |
||
81 | */ |
||
82 | public function getSize() { |
||
89 | |||
90 | /** |
||
91 | * Return the path to the temporary file |
||
92 | * |
||
93 | * @return string|null Path or null if non-existent |
||
94 | */ |
||
95 | public function getTempName() { |
||
102 | |||
103 | /** |
||
104 | * Return the upload error. See link for explanation |
||
105 | * https://secure.php.net/manual/en/features.file-upload.errors.php |
||
106 | * |
||
107 | * @return int One of the UPLOAD_ constants, 0 if non-existent |
||
108 | */ |
||
109 | public function getError() { |
||
116 | |||
117 | /** |
||
118 | * Returns whether this upload failed because of overflow of a maximum set |
||
119 | * in php.ini |
||
120 | * |
||
121 | * @return bool |
||
122 | */ |
||
123 | public function isIniSizeOverflow() { |
||
142 | } |
||
143 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: