Code Duplication    Length = 39-39 lines in 2 locations

class/SwUploadHandler.php 1 location

@@ 199-237 (lines=39) @@
196
        echo json_encode($info);
197
    }
198
199
    public function post()
200
    {
201
        $upload = isset($_FILES[$this->field_name]) ? $_FILES[$this->field_name] : [
202
            'tmp_name' => null,
203
            'name'     => null,
204
            'size'     => null,
205
            'type'     => null,
206
            'error'    => null,
207
        ];
208
        if (is_array($upload['tmp_name']) && count($upload['tmp_name']) > 1) {
209
            $info = [];
210
            foreach ($upload['tmp_name'] as $index => $value) {
211
                $info[] = $this->handle_file_upload($upload['tmp_name'][$index], $upload['name'][$index], $upload['size'][$index], $upload['type'][$index], $upload['error'][$index]);
212
            }
213
        } else {
214
            if (is_array($upload['tmp_name'])) {
215
                $upload = [
216
                    'tmp_name' => $upload['tmp_name'][0],
217
                    'name'     => $upload['name'][0],
218
                    'size'     => $upload['size'][0],
219
                    'type'     => $upload['type'][0],
220
                    'error'    => $upload['error'][0],
221
                ];
222
            }
223
            $info = $this->handle_file_upload(
224
                $upload['tmp_name'],
225
                isset($_SERVER['HTTP_X_FILE_NAME']) ? $_SERVER['HTTP_X_FILE_NAME'] : $upload['name'],
226
                isset($_SERVER['HTTP_X_FILE_SIZE']) ? $_SERVER['HTTP_X_FILE_SIZE'] : $upload['size'],
227
                isset($_SERVER['HTTP_X_FILE_TYPE']) ? $_SERVER['HTTP_X_FILE_TYPE'] : $upload['type'],
228
                $upload['error']
229
            );
230
        }
231
        if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && 'XMLHttpRequest' === $_SERVER['HTTP_X_REQUESTED_WITH']) {
232
            header('Content-type: application/json');
233
        } else {
234
            header('Content-type: text/plain');
235
        }
236
        echo json_encode($info);
237
    }
238
239
    public function delete()
240
    {

class/uploadclass.php 1 location

@@ 189-227 (lines=39) @@
186
        echo json_encode($info);
187
    }
188
189
    public function post()
190
    {
191
        $upload = isset($_FILES[$this->field_name]) ? $_FILES[$this->field_name] : [
192
            'tmp_name' => null,
193
            'name'     => null,
194
            'size'     => null,
195
            'type'     => null,
196
            'error'    => null
197
        ];
198
        if (is_array($upload['tmp_name']) && count($upload['tmp_name']) > 1) {
199
            $info = [];
200
            foreach ($upload['tmp_name'] as $index => $value) {
201
                $info[] = $this->handle_file_upload($upload['tmp_name'][$index], $upload['name'][$index], $upload['size'][$index], $upload['type'][$index], $upload['error'][$index]);
202
            }
203
        } else {
204
            if (is_array($upload['tmp_name'])) {
205
                $upload = [
206
                    'tmp_name' => $upload['tmp_name'][0],
207
                    'name'     => $upload['name'][0],
208
                    'size'     => $upload['size'][0],
209
                    'type'     => $upload['type'][0],
210
                    'error'    => $upload['error'][0]
211
                ];
212
            }
213
            $info = $this->handle_file_upload(
214
                $upload['tmp_name'],
215
                isset($_SERVER['HTTP_X_FILE_NAME']) ? $_SERVER['HTTP_X_FILE_NAME'] : $upload['name'],
216
                isset($_SERVER['HTTP_X_FILE_SIZE']) ? $_SERVER['HTTP_X_FILE_SIZE'] : $upload['size'],
217
                                              isset($_SERVER['HTTP_X_FILE_TYPE']) ? $_SERVER['HTTP_X_FILE_TYPE'] : $upload['type'],
218
                $upload['error']
219
            );
220
        }
221
        if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && 'XMLHttpRequest' === $_SERVER['HTTP_X_REQUESTED_WITH']) {
222
            header('Content-type: application/json');
223
        } else {
224
            header('Content-type: text/plain');
225
        }
226
        echo json_encode($info);
227
    }
228
229
    public function delete()
230
    {