1
1
<?php
2
2
/*
3
- * jQuery File Upload Plugin PHP Class 5.12
3
+ * jQuery File Upload Plugin PHP Class 5.13
4
4
* https://github.com/blueimp/jQuery-File-Upload
5
5
*
6
6
* Copyright 2010, Sebastian Tschan
@@ -86,13 +86,13 @@ function __construct($options=null) {
86
86
87
87
protected function get_full_url () {
88
88
$ https = !empty ($ _SERVER ['HTTPS ' ]) && $ _SERVER ['HTTPS ' ] !== 'off ' ;
89
- return
90
- ($ https ? 'https:// ' : 'http:// ' ).
91
- (!empty ($ _SERVER ['REMOTE_USER ' ]) ? $ _SERVER ['REMOTE_USER ' ].'@ ' : '' ).
92
- (isset ($ _SERVER ['HTTP_HOST ' ]) ? $ _SERVER ['HTTP_HOST ' ] : ($ _SERVER ['SERVER_NAME ' ].
93
- ($ https && $ _SERVER ['SERVER_PORT ' ] === 443 ||
94
- $ _SERVER ['SERVER_PORT ' ] === 80 ? '' : ': ' .$ _SERVER ['SERVER_PORT ' ]))).
95
- substr ($ _SERVER ['SCRIPT_NAME ' ],0 , strrpos ($ _SERVER ['SCRIPT_NAME ' ], '/ ' ));
89
+ return
90
+ ($ https ? 'https:// ' : 'http:// ' ).
91
+ (!empty ($ _SERVER ['REMOTE_USER ' ]) ? $ _SERVER ['REMOTE_USER ' ].'@ ' : '' ).
92
+ (isset ($ _SERVER ['HTTP_HOST ' ]) ? $ _SERVER ['HTTP_HOST ' ] : ($ _SERVER ['SERVER_NAME ' ].
93
+ ($ https && $ _SERVER ['SERVER_PORT ' ] === 443 ||
94
+ $ _SERVER ['SERVER_PORT ' ] === 80 ? '' : ': ' .$ _SERVER ['SERVER_PORT ' ]))).
95
+ substr ($ _SERVER ['SCRIPT_NAME ' ],0 , strrpos ($ _SERVER ['SCRIPT_NAME ' ], '/ ' ));
96
96
}
97
97
98
98
protected function set_file_delete_url ($ file ) {
@@ -104,12 +104,25 @@ protected function set_file_delete_url($file) {
104
104
}
105
105
}
106
106
107
+ protected function get_file_size ($ file_path , $ clear_stat_cache = false ) {
108
+ if ($ clear_stat_cache ) {
109
+ clearstatcache ();
110
+ }
111
+ $ size = filesize ($ file_path );
112
+ if ($ size < 0 ) {
113
+ // Fix for overflowing signed 32 bit integers,
114
+ // works for files up to 2^32-1 bytes (4 GiB - 1) in size:
115
+ $ size += 2.0 * (PHP_INT_MAX + 1 );
116
+ }
117
+ return $ size ;
118
+ }
119
+
107
120
protected function get_file_object ($ file_name ) {
108
121
$ file_path = $ this ->options ['upload_dir ' ].$ file_name ;
109
122
if (is_file ($ file_path ) && $ file_name [0 ] !== '. ' ) {
110
123
$ file = new stdClass ();
111
124
$ file ->name = $ file_name ;
112
- $ file ->size = filesize ($ file_path );
125
+ $ file ->size = $ this -> get_file_size ($ file_path );
113
126
$ file ->url = $ this ->options ['upload_url ' ].rawurlencode ($ file ->name );
114
127
foreach ($ this ->options ['image_versions ' ] as $ version => $ options ) {
115
128
if (is_file ($ options ['upload_dir ' ].$ file_name )) {
@@ -210,7 +223,7 @@ protected function validate($uploaded_file, $file, $error, $index) {
210
223
return false ;
211
224
}
212
225
if ($ uploaded_file && is_uploaded_file ($ uploaded_file )) {
213
- $ file_size = filesize ($ uploaded_file );
226
+ $ file_size = $ this -> get_file_size ($ uploaded_file );
214
227
} else {
215
228
$ file_size = $ _SERVER ['CONTENT_LENGTH ' ];
216
229
}
@@ -292,32 +305,32 @@ protected function handle_form_data($file, $index) {
292
305
}
293
306
294
307
protected function orient_image ($ file_path ) {
295
- $ exif = @exif_read_data ($ file_path );
308
+ $ exif = @exif_read_data ($ file_path );
296
309
if ($ exif === false ) {
297
310
return false ;
298
311
}
299
- $ orientation = intval (@$ exif ['Orientation ' ]);
300
- if (!in_array ($ orientation , array (3 , 6 , 8 ))) {
301
- return false ;
302
- }
303
- $ image = @imagecreatefromjpeg ($ file_path );
304
- switch ($ orientation ) {
305
- case 3 :
306
- $ image = @imagerotate ($ image , 180 , 0 );
307
- break ;
308
- case 6 :
309
- $ image = @imagerotate ($ image , 270 , 0 );
310
- break ;
311
- case 8 :
312
- $ image = @imagerotate ($ image , 90 , 0 );
313
- break ;
314
- default :
315
- return false ;
316
- }
317
- $ success = imagejpeg ($ image , $ file_path );
318
- // Free up memory (imagedestroy does not delete files):
319
- @imagedestroy ($ image );
320
- return $ success ;
312
+ $ orientation = intval (@$ exif ['Orientation ' ]);
313
+ if (!in_array ($ orientation , array (3 , 6 , 8 ))) {
314
+ return false ;
315
+ }
316
+ $ image = @imagecreatefromjpeg ($ file_path );
317
+ switch ($ orientation ) {
318
+ case 3 :
319
+ $ image = @imagerotate ($ image , 180 , 0 );
320
+ break ;
321
+ case 6 :
322
+ $ image = @imagerotate ($ image , 270 , 0 );
323
+ break ;
324
+ case 8 :
325
+ $ image = @imagerotate ($ image , 90 , 0 );
326
+ break ;
327
+ default :
328
+ return false ;
329
+ }
330
+ $ success = imagejpeg ($ image , $ file_path );
331
+ // Free up memory (imagedestroy does not delete files):
332
+ @imagedestroy ($ image );
333
+ return $ success ;
321
334
}
322
335
323
336
protected function handle_file_upload ($ uploaded_file , $ name , $ size , $ type , $ error , $ index = null ) {
@@ -329,8 +342,7 @@ protected function handle_file_upload($uploaded_file, $name, $size, $type, $erro
329
342
$ this ->handle_form_data ($ file , $ index );
330
343
$ file_path = $ this ->options ['upload_dir ' ].$ file ->name ;
331
344
$ append_file = !$ this ->options ['discard_aborted_uploads ' ] &&
332
- is_file ($ file_path ) && $ file ->size > filesize ($ file_path );
333
- clearstatcache ();
345
+ is_file ($ file_path ) && $ file ->size > $ this ->get_file_size ($ file_path );
334
346
if ($ uploaded_file && is_uploaded_file ($ uploaded_file )) {
335
347
// multipart/formdata uploads (POST method uploads)
336
348
if ($ append_file ) {
@@ -350,20 +362,19 @@ protected function handle_file_upload($uploaded_file, $name, $size, $type, $erro
350
362
$ append_file ? FILE_APPEND : 0
351
363
);
352
364
}
353
- $ file_size = filesize ($ file_path );
365
+ $ file_size = $ this -> get_file_size ($ file_path, $ append_file );
354
366
if ($ file_size === $ file ->size ) {
355
- if ($ this ->options ['orient_image ' ]) {
356
- $ this ->orient_image ($ file_path );
357
- }
367
+ if ($ this ->options ['orient_image ' ]) {
368
+ $ this ->orient_image ($ file_path );
369
+ }
358
370
$ file ->url = $ this ->options ['upload_url ' ].rawurlencode ($ file ->name );
359
371
foreach ($ this ->options ['image_versions ' ] as $ version => $ options ) {
360
372
if ($ this ->create_scaled_image ($ file ->name , $ options )) {
361
373
if ($ this ->options ['upload_dir ' ] !== $ options ['upload_dir ' ]) {
362
374
$ file ->{$ version .'_url ' } = $ options ['upload_url ' ]
363
375
.rawurlencode ($ file ->name );
364
376
} else {
365
- clearstatcache ();
366
- $ file_size = filesize ($ file_path );
377
+ $ file_size = $ this ->get_file_size ($ file_path , true );
367
378
}
368
379
}
369
380
}
0 commit comments