Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
34 / 34 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
form | |
100.00% |
34 / 34 |
|
100.00% |
3 / 3 |
11 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
upload | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
form_upload | |
100.00% |
27 / 27 |
|
100.00% |
1 / 1 |
9 |
1 | <?php |
2 | /** |
3 | * |
4 | * This file is part of the phpBB Forum Software package. |
5 | * |
6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
7 | * @license GNU General Public License, version 2 (GPL-2.0) |
8 | * |
9 | * For full copyright and license information, please see |
10 | * the docs/CREDITS.txt file. |
11 | * |
12 | */ |
13 | |
14 | namespace phpbb\files\types; |
15 | |
16 | use bantu\IniGetWrapper\IniGetWrapper; |
17 | use phpbb\files\factory; |
18 | use phpbb\files\filespec; |
19 | use phpbb\language\language; |
20 | use phpbb\plupload\plupload; |
21 | use phpbb\request\request; |
22 | |
23 | class form extends base |
24 | { |
25 | /** @var factory Files factory */ |
26 | protected $factory; |
27 | |
28 | /** @var plupload */ |
29 | protected $plupload; |
30 | |
31 | /** @var request */ |
32 | protected $request; |
33 | |
34 | /** |
35 | * Construct a form upload type |
36 | * |
37 | * @param factory $factory Files factory |
38 | * @param language $language Language class |
39 | * @param IniGetWrapper $php_ini ini_get() wrapper |
40 | * @param plupload $plupload Plupload |
41 | * @param request $request Request object |
42 | */ |
43 | public function __construct(factory $factory, language $language, IniGetWrapper $php_ini, plupload $plupload, request $request) |
44 | { |
45 | $this->factory = $factory; |
46 | $this->language = $language; |
47 | $this->php_ini = $php_ini; |
48 | $this->plupload = $plupload; |
49 | $this->request = $request; |
50 | } |
51 | |
52 | /** |
53 | * {@inheritdoc} |
54 | */ |
55 | public function upload() |
56 | { |
57 | $args = func_get_args(); |
58 | return $this->form_upload($args[0]); |
59 | } |
60 | |
61 | /** |
62 | * Form upload method |
63 | * Upload file from users harddisk |
64 | * |
65 | * @param string $form_name Form name assigned to the file input field (if it is an array, the key has to be specified) |
66 | * |
67 | * @return filespec $file Object "filespec" is returned, all further operations can be done with this object |
68 | * @access public |
69 | */ |
70 | protected function form_upload($form_name) |
71 | { |
72 | $upload = $this->request->file($form_name); |
73 | unset($upload['local_mode']); |
74 | |
75 | $result = $this->plupload->handle_upload($form_name); |
76 | if (is_array($result)) |
77 | { |
78 | $upload = array_merge($upload, $result); |
79 | } |
80 | |
81 | /** @var filespec $file */ |
82 | $file = $this->factory->get('filespec') |
83 | ->set_upload_ary($upload) |
84 | ->set_upload_namespace($this->upload); |
85 | |
86 | if ($file->init_error()) |
87 | { |
88 | $file->error[] = ''; |
89 | return $file; |
90 | } |
91 | |
92 | // Error array filled? |
93 | if (isset($upload['error'])) |
94 | { |
95 | $error = $this->upload->assign_internal_error($upload['error']); |
96 | |
97 | if ($error !== false) |
98 | { |
99 | $file->error[] = $error; |
100 | return $file; |
101 | } |
102 | } |
103 | |
104 | // Check if empty file got uploaded (not catched by is_uploaded_file) |
105 | if (isset($upload['size']) && $upload['size'] == 0) |
106 | { |
107 | $file->error[] = $this->language->lang($this->upload->error_prefix . 'EMPTY_FILEUPLOAD'); |
108 | return $file; |
109 | } |
110 | |
111 | // PHP Upload file size check |
112 | $file = $this->check_upload_size($file); |
113 | if (count($file->error)) |
114 | { |
115 | return $file; |
116 | } |
117 | |
118 | // Not correctly uploaded |
119 | if (!$file->is_uploaded()) |
120 | { |
121 | $file->error[] = $this->language->lang($this->upload->error_prefix . 'NOT_UPLOADED'); |
122 | return $file; |
123 | } |
124 | |
125 | $this->upload->common_checks($file); |
126 | |
127 | return $file; |
128 | } |
129 | } |