Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/http-foundation/File/UploadedFile.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 4c8ae668cc8c |
children | c2387f117808 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
22 * @author Florian Eckerstorfer <florian@eckerstorfer.org> | 22 * @author Florian Eckerstorfer <florian@eckerstorfer.org> |
23 * @author Fabien Potencier <fabien@symfony.com> | 23 * @author Fabien Potencier <fabien@symfony.com> |
24 */ | 24 */ |
25 class UploadedFile extends File | 25 class UploadedFile extends File |
26 { | 26 { |
27 /** | |
28 * Whether the test mode is activated. | |
29 * | |
30 * Local files are used in test mode hence the code should not enforce HTTP uploads. | |
31 * | |
32 * @var bool | |
33 */ | |
34 private $test = false; | 27 private $test = false; |
35 | |
36 /** | |
37 * The original name of the uploaded file. | |
38 * | |
39 * @var string | |
40 */ | |
41 private $originalName; | 28 private $originalName; |
42 | |
43 /** | |
44 * The mime type provided by the uploader. | |
45 * | |
46 * @var string | |
47 */ | |
48 private $mimeType; | 29 private $mimeType; |
49 | |
50 /** | |
51 * The file size provided by the uploader. | |
52 * | |
53 * @var int|null | |
54 */ | |
55 private $size; | 30 private $size; |
56 | |
57 /** | |
58 * The UPLOAD_ERR_XXX constant provided by the uploader. | |
59 * | |
60 * @var int | |
61 */ | |
62 private $error; | 31 private $error; |
63 | 32 |
64 /** | 33 /** |
65 * Accepts the information of the uploaded file as provided by the PHP global $_FILES. | 34 * Accepts the information of the uploaded file as provided by the PHP global $_FILES. |
66 * | 35 * |
74 * * getError. | 43 * * getError. |
75 * | 44 * |
76 * Calling any other method on an non-valid instance will cause an unpredictable result. | 45 * Calling any other method on an non-valid instance will cause an unpredictable result. |
77 * | 46 * |
78 * @param string $path The full temporary path to the file | 47 * @param string $path The full temporary path to the file |
79 * @param string $originalName The original file name | 48 * @param string $originalName The original file name of the uploaded file |
80 * @param string|null $mimeType The type of the file as provided by PHP; null defaults to application/octet-stream | 49 * @param string|null $mimeType The type of the file as provided by PHP; null defaults to application/octet-stream |
81 * @param int|null $size The file size | 50 * @param int|null $size The file size provided by the uploader |
82 * @param int|null $error The error constant of the upload (one of PHP's UPLOAD_ERR_XXX constants); null defaults to UPLOAD_ERR_OK | 51 * @param int|null $error The error constant of the upload (one of PHP's UPLOAD_ERR_XXX constants); null defaults to UPLOAD_ERR_OK |
83 * @param bool $test Whether the test mode is active | 52 * @param bool $test Whether the test mode is active |
53 * Local files are used in test mode hence the code should not enforce HTTP uploads | |
84 * | 54 * |
85 * @throws FileException If file_uploads is disabled | 55 * @throws FileException If file_uploads is disabled |
86 * @throws FileNotFoundException If the file does not exist | 56 * @throws FileNotFoundException If the file does not exist |
87 */ | 57 */ |
88 public function __construct($path, $originalName, $mimeType = null, $size = null, $error = null, $test = false) | 58 public function __construct($path, $originalName, $mimeType = null, $size = null, $error = null, $test = false) |
196 * | 166 * |
197 * @return bool True if the file has been uploaded with HTTP and no error occurred | 167 * @return bool True if the file has been uploaded with HTTP and no error occurred |
198 */ | 168 */ |
199 public function isValid() | 169 public function isValid() |
200 { | 170 { |
201 $isOk = $this->error === UPLOAD_ERR_OK; | 171 $isOk = UPLOAD_ERR_OK === $this->error; |
202 | 172 |
203 return $this->test ? $isOk : $isOk && is_uploaded_file($this->getPathname()); | 173 return $this->test ? $isOk : $isOk && is_uploaded_file($this->getPathname()); |
204 } | 174 } |
205 | 175 |
206 /** | 176 /** |
257 $max = (int) $max; | 227 $max = (int) $max; |
258 } | 228 } |
259 | 229 |
260 switch (substr($iniMax, -1)) { | 230 switch (substr($iniMax, -1)) { |
261 case 't': $max *= 1024; | 231 case 't': $max *= 1024; |
232 // no break | |
262 case 'g': $max *= 1024; | 233 case 'g': $max *= 1024; |
234 // no break | |
263 case 'm': $max *= 1024; | 235 case 'm': $max *= 1024; |
236 // no break | |
264 case 'k': $max *= 1024; | 237 case 'k': $max *= 1024; |
265 } | 238 } |
266 | 239 |
267 return $max; | 240 return $max; |
268 } | 241 } |
283 UPLOAD_ERR_NO_TMP_DIR => 'File could not be uploaded: missing temporary directory.', | 256 UPLOAD_ERR_NO_TMP_DIR => 'File could not be uploaded: missing temporary directory.', |
284 UPLOAD_ERR_EXTENSION => 'File upload was stopped by a PHP extension.', | 257 UPLOAD_ERR_EXTENSION => 'File upload was stopped by a PHP extension.', |
285 ); | 258 ); |
286 | 259 |
287 $errorCode = $this->error; | 260 $errorCode = $this->error; |
288 $maxFilesize = $errorCode === UPLOAD_ERR_INI_SIZE ? self::getMaxFilesize() / 1024 : 0; | 261 $maxFilesize = UPLOAD_ERR_INI_SIZE === $errorCode ? self::getMaxFilesize() / 1024 : 0; |
289 $message = isset($errors[$errorCode]) ? $errors[$errorCode] : 'The file "%s" was not uploaded due to an unknown error.'; | 262 $message = isset($errors[$errorCode]) ? $errors[$errorCode] : 'The file "%s" was not uploaded due to an unknown error.'; |
290 | 263 |
291 return sprintf($message, $this->getClientOriginalName(), $maxFilesize); | 264 return sprintf($message, $this->getClientOriginalName(), $maxFilesize); |
292 } | 265 } |
293 } | 266 } |