forked from tad0616/street_news
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class.upload.php
5008 lines (4656 loc) · 241 KB
/
class.upload.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
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
// +------------------------------------------------------------------------+
// | class.upload.php |
// +------------------------------------------------------------------------+
// | Copyright (c) Colin Verot 2003-2014. All rights reserved. |
// | Email [email protected] |
// | Web http://www.verot.net |
// +------------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or modify |
// | it under the terms of the GNU General Public License version 2 as |
// | published by the Free Software Foundation. |
// | |
// | This program is distributed in the hope that it will be useful, |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
// | GNU General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with this program; if not, write to the |
// | Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
// | Boston, MA 02111-1307 USA |
// | |
// | Please give credit on sites that use class.upload and submit changes |
// | of the script so other people can use them as well. |
// | This script is free to use, don't abuse. |
// +------------------------------------------------------------------------+
/**
* Class upload
*
* @author Colin Verot <[email protected]>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @copyright Colin Verot
*/
class upload {
/**
* Class version
*
* @access public
* @var string
*/
var $version;
/**
* Uploaded file name
*
* @access public
* @var string
*/
var $file_src_name;
/**
* Uploaded file name body (i.e. without extension)
*
* @access public
* @var string
*/
var $file_src_name_body;
/**
* Uploaded file name extension
*
* @access public
* @var string
*/
var $file_src_name_ext;
/**
* Uploaded file MIME type
*
* @access public
* @var string
*/
var $file_src_mime;
/**
* Uploaded file size, in bytes
*
* @access public
* @var double
*/
var $file_src_size;
/**
* Holds eventual PHP error code from $_FILES
*
* @access public
* @var string
*/
var $file_src_error;
/**
* Uloaded file name, including server path
*
* @access public
* @var string
*/
var $file_src_pathname;
/**
* Uloaded file name temporary copy
*
* @access private
* @var string
*/
var $file_src_temp;
/**
* Destination file name
*
* @access public
* @var string
*/
var $file_dst_path;
/**
* Destination file name
*
* @access public
* @var string
*/
var $file_dst_name;
/**
* Destination file name body (i.e. without extension)
*
* @access public
* @var string
*/
var $file_dst_name_body;
/**
* Destination file extension
*
* @access public
* @var string
*/
var $file_dst_name_ext;
/**
* Destination file name, including path
*
* @access public
* @var string
*/
var $file_dst_pathname;
/**
* Source image width
*
* @access public
* @var integer
*/
var $image_src_x;
/**
* Source image height
*
* @access public
* @var integer
*/
var $image_src_y;
/**
* Source image color depth
*
* @access public
* @var integer
*/
var $image_src_bits;
/**
* Number of pixels
*
* @access public
* @var long
*/
var $image_src_pixels;
/**
* Type of image (png, gif, jpg or bmp)
*
* @access public
* @var string
*/
var $image_src_type;
/**
* Destination image width
*
* @access public
* @var integer
*/
var $image_dst_x;
/**
* Destination image height
*
* @access public
* @var integer
*/
var $image_dst_y;
/**
* Destination image type (png, gif, jpg or bmp)
*
* @access public
* @var integer
*/
var $image_dst_type;
/**
* Supported image formats
*
* @access private
* @var array
*/
var $image_supported;
/**
* Flag to determine if the source file is an image
*
* @access public
* @var boolean
*/
var $file_is_image;
/**
* Flag set after instanciating the class
*
* Indicates if the file has been uploaded properly
*
* @access public
* @var bool
*/
var $uploaded;
/**
* Flag stopping PHP upload checks
*
* Indicates whether we instanciated the class with a filename, in which case
* we will not check on the validity of the PHP *upload*
*
* This flag is automatically set to true when working on a local file
*
* Warning: for uploads, this flag MUST be set to false for security reason
*
* @access public
* @var bool
*/
var $no_upload_check;
/**
* Flag set after calling a process
*
* Indicates if the processing, and copy of the resulting file went OK
*
* @access public
* @var bool
*/
var $processed;
/**
* Holds eventual error message in plain english
*
* @access public
* @var string
*/
var $error;
/**
* Holds an HTML formatted log
*
* @access public
* @var string
*/
var $log;
// overiddable processing variables
/**
* Set this variable to replace the name body (i.e. without extension)
*
* @access public
* @var string
*/
var $file_new_name_body;
/**
* Set this variable to append a string to the file name body
*
* @access public
* @var string
*/
var $file_name_body_add;
/**
* Set this variable to prepend a string to the file name body
*
* @access public
* @var string
*/
var $file_name_body_pre;
/**
* Set this variable to change the file extension
*
* @access public
* @var string
*/
var $file_new_name_ext;
/**
* Set this variable to format the filename (spaces changed to _)
*
* @access public
* @var boolean
*/
var $file_safe_name;
/**
* Forces an extension if the source file doesn't have one
*
* If the file is an image, then the correct extension will be added
* Otherwise, a .txt extension will be chosen
*
* @access public
* @var boolean
*/
var $file_force_extension;
/**
* Set this variable to false if you don't want to check the MIME against the allowed list
*
* This variable is set to true by default for security reason
*
* @access public
* @var boolean
*/
var $mime_check;
/**
* Set this variable to false in the init() function if you don't want to check the MIME
* with Fileinfo PECL extension. On some systems, Fileinfo is known to be buggy, and you
* may want to deactivate it in the class code directly.
*
* You can also set it with the path of the magic database file.
* If set to true, the class will try to read the MAGIC environment variable
* and if it is empty, will default to the system's default
* If set to an empty string, it will call finfo_open without the path argument
*
* This variable is set to true by default for security reason
*
* @access public
* @var boolean
*/
var $mime_fileinfo;
/**
* Set this variable to false in the init() function if you don't want to check the MIME
* with UNIX file() command
*
* This variable is set to true by default for security reason
*
* @access public
* @var boolean
*/
var $mime_file;
/**
* Set this variable to false in the init() function if you don't want to check the MIME
* with the magic.mime file
*
* The function mime_content_type() will be deprecated,
* and this variable will be set to false in a future release
*
* This variable is set to true by default for security reason
*
* @access public
* @var boolean
*/
var $mime_magic;
/**
* Set this variable to false in the init() function if you don't want to check the MIME
* with getimagesize()
*
* The class tries to get a MIME type from getimagesize()
* If no MIME is returned, it tries to guess the MIME type from the file type
*
* This variable is set to true by default for security reason
*
* @access public
* @var boolean
*/
var $mime_getimagesize;
/**
* Set this variable to false if you don't want to turn dangerous scripts into simple text files
*
* @access public
* @var boolean
*/
var $no_script;
/**
* Set this variable to true to allow automatic renaming of the file
* if the file already exists
*
* Default value is true
*
* For instance, on uploading foo.ext,<br>
* if foo.ext already exists, upload will be renamed foo_1.ext<br>
* and if foo_1.ext already exists, upload will be renamed foo_2.ext<br>
*
* Note that this option doesn't have any effect if {@link file_overwrite} is true
*
* @access public
* @var bool
*/
var $file_auto_rename;
/**
* Set this variable to true to allow automatic creation of the destination
* directory if it is missing (works recursively)
*
* Default value is true
*
* @access public
* @var bool
*/
var $dir_auto_create;
/**
* Set this variable to true to allow automatic chmod of the destination
* directory if it is not writeable
*
* Default value is true
*
* @access public
* @var bool
*/
var $dir_auto_chmod;
/**
* Set this variable to the default chmod you want the class to use
* when creating directories, or attempting to write in a directory
*
* Default value is 0777 (without quotes)
*
* @access public
* @var bool
*/
var $dir_chmod;
/**
* Set this variable tu true to allow overwriting of an existing file
*
* Default value is false, so no files will be overwritten
*
* @access public
* @var bool
*/
var $file_overwrite;
/**
* Set this variable to change the maximum size in bytes for an uploaded file
*
* Default value is the value <i>upload_max_filesize</i> from php.ini
*
* Value in bytes (integer) or shorthand byte values (string) is allowed.
* The available options are K (for Kilobytes), M (for Megabytes) and G (for Gigabytes)
*
* @access public
* @var double
*/
var $file_max_size;
/**
* Set this variable to true to resize the file if it is an image
*
* You will probably want to set {@link image_x} and {@link image_y}, and maybe one of the ratio variables
*
* Default value is false (no resizing)
*
* @access public
* @var bool
*/
var $image_resize;
/**
* Set this variable to convert the file if it is an image
*
* Possibles values are : ''; 'png'; 'jpeg'; 'gif'; 'bmp'
*
* Default value is '' (no conversion)<br>
* If {@link resize} is true, {@link convert} will be set to the source file extension
*
* @access public
* @var string
*/
var $image_convert;
/**
* Set this variable to the wanted (or maximum/minimum) width for the processed image, in pixels
*
* Default value is 150
*
* @access public
* @var integer
*/
var $image_x;
/**
* Set this variable to the wanted (or maximum/minimum) height for the processed image, in pixels
*
* Default value is 150
*
* @access public
* @var integer
*/
var $image_y;
/**
* Set this variable to keep the original size ratio to fit within {@link image_x} x {@link image_y}
*
* Default value is false
*
* @access public
* @var bool
*/
var $image_ratio;
/**
* Set this variable to keep the original size ratio to fit within {@link image_x} x {@link image_y}
*
* The image will be resized as to fill the whole space, and excedent will be cropped
*
* Value can also be a string, one or more character from 'TBLR' (top, bottom, left and right)
* If set as a string, it determines which side of the image is kept while cropping.
* By default, the part of the image kept is in the center, i.e. it crops equally on both sides
*
* Default value is false
*
* @access public
* @var mixed
*/
var $image_ratio_crop;
/**
* Set this variable to keep the original size ratio to fit within {@link image_x} x {@link image_y}
*
* The image will be resized to fit entirely in the space, and the rest will be colored.
* The default color is white, but can be set with {@link image_default_color}
*
* Value can also be a string, one or more character from 'TBLR' (top, bottom, left and right)
* If set as a string, it determines in which side of the space the image is displayed.
* By default, the image is displayed in the center, i.e. it fills the remaining space equally on both sides
*
* Default value is false
*
* @access public
* @var mixed
*/
var $image_ratio_fill;
/**
* Set this variable to a number of pixels so that {@link image_x} and {@link image_y} are the best match possible
*
* The image will be resized to have approximatively the number of pixels
* The aspect ratio wil be conserved
*
* Default value is false
*
* @access public
* @var mixed
*/
var $image_ratio_pixels;
/**
* Set this variable to calculate {@link image_x} automatically , using {@link image_y} and conserving ratio
*
* Default value is false
*
* @access public
* @var bool
*/
var $image_ratio_x;
/**
* Set this variable to calculate {@link image_y} automatically , using {@link image_x} and conserving ratio
*
* Default value is false
*
* @access public
* @var bool
*/
var $image_ratio_y;
/**
* (deprecated) Set this variable to keep the original size ratio to fit within {@link image_x} x {@link image_y},
* but only if original image is bigger
*
* This setting is soon to be deprecated. Instead, use {@link image_ratio} and {@link image_no_enlarging}
*
* Default value is false
*
* @access public
* @var bool
*/
var $image_ratio_no_zoom_in;
/**
* (deprecated) Set this variable to keep the original size ratio to fit within {@link image_x} x {@link image_y},
* but only if original image is smaller
*
* Default value is false
*
* This setting is soon to be deprecated. Instead, use {@link image_ratio} and {@link image_no_shrinking}
*
* @access public
* @var bool
*/
var $image_ratio_no_zoom_out;
/**
* Cancel resizing if the resized image is bigger than the original image, to prevent enlarging
*
* Default value is false
*
* @access public
* @var bool
*/
var $image_no_enlarging;
/**
* Cancel resizing if the resized image is smaller than the original image, to prevent shrinking
*
* Default value is false
*
* @access public
* @var bool
*/
var $image_no_shrinking;
/**
* Set this variable to set a maximum image width, above which the upload will be invalid
*
* Default value is null
*
* @access public
* @var integer
*/
var $image_max_width;
/**
* Set this variable to set a maximum image height, above which the upload will be invalid
*
* Default value is null
*
* @access public
* @var integer
*/
var $image_max_height;
/**
* Set this variable to set a maximum number of pixels for an image, above which the upload will be invalid
*
* Default value is null
*
* @access public
* @var long
*/
var $image_max_pixels;
/**
* Set this variable to set a maximum image aspect ratio, above which the upload will be invalid
*
* Note that ratio = width / height
*
* Default value is null
*
* @access public
* @var float
*/
var $image_max_ratio;
/**
* Set this variable to set a minimum image width, below which the upload will be invalid
*
* Default value is null
*
* @access public
* @var integer
*/
var $image_min_width;
/**
* Set this variable to set a minimum image height, below which the upload will be invalid
*
* Default value is null
*
* @access public
* @var integer
*/
var $image_min_height;
/**
* Set this variable to set a minimum number of pixels for an image, below which the upload will be invalid
*
* Default value is null
*
* @access public
* @var long
*/
var $image_min_pixels;
/**
* Set this variable to set a minimum image aspect ratio, below which the upload will be invalid
*
* Note that ratio = width / height
*
* Default value is null
*
* @access public
* @var float
*/
var $image_min_ratio;
/**
* Compression level for PNG images
*
* Between 1 (fast but large files) and 9 (slow but smaller files)
*
* Default value is null (Zlib default)
*
* @access public
* @var integer
*/
var $png_compression;
/**
* Quality of JPEG created/converted destination image
*
* Default value is 85
*
* @access public
* @var integer
*/
var $jpeg_quality;
/**
* Determines the quality of the JPG image to fit a desired file size
*
* The JPG quality will be set between 1 and 100%
* The calculations are approximations.
*
* Value in bytes (integer) or shorthand byte values (string) is allowed.
* The available options are K (for Kilobytes), M (for Megabytes) and G (for Gigabytes)
*
* Default value is null (no calculations)
*
* @access public
* @var integer
*/
var $jpeg_size;
/**
* Turns the interlace bit on
*
* This is actually used only for JPEG images, and defaults to false
*
* @access public
* @var boolean
*/
var $image_interlace;
/**
* Flag set to true when the image is transparent
*
* This is actually used only for transparent GIFs
*
* @access public
* @var boolean
*/
var $image_is_transparent;
/**
* Transparent color in a palette
*
* This is actually used only for transparent GIFs
*
* @access public
* @var boolean
*/
var $image_transparent_color;
/**
* Background color, used to paint transparent areas with
*
* If set, it will forcibly remove transparency by painting transparent areas with the color
* This setting will fill in all transparent areas in PNG and GIF, as opposed to {@link image_default_color}
* which will do so only in BMP, JPEG, and alpha transparent areas in transparent GIFs
* This setting overrides {@link image_default_color}
*
* Default value is null
*
* @access public
* @var string
*/
var $image_background_color;
/**
* Default color for non alpha-transparent images
*
* This setting is to be used to define a background color for semi transparent areas
* of an alpha transparent when the output format doesn't support alpha transparency
* This is useful when, from an alpha transparent PNG image, or an image with alpha transparent features
* if you want to output it as a transparent GIFs for instance, you can set a blending color for transparent areas
* If you output in JPEG or BMP, this color will be used to fill in the previously transparent areas
*
* The default color white
*
* @access public
* @var boolean
*/
var $image_default_color;
/**
* Flag set to true when the image is not true color
*
* @access public
* @var boolean
*/
var $image_is_palette;
/**
* Corrects the image brightness
*
* Value can range between -127 and 127
*
* Default value is null
*
* @access public
* @var integer
*/
var $image_brightness;
/**
* Corrects the image contrast
*
* Value can range between -127 and 127
*
* Default value is null
*
* @access public
* @var integer
*/
var $image_contrast;
/**
* Changes the image opacity
*
* Value can range between 0 and 100
*
* Default value is null
*
* @access public
* @var integer
*/
var $image_opacity;
/**
* Applies threshold filter
*
* Value can range between -127 and 127
*
* Default value is null
*
* @access public
* @var integer
*/
var $image_threshold;
/**
* Applies a tint on the image
*
* Value is an hexadecimal color, such as #FFFFFF
*
* Default value is null
*
* @access public
* @var string;
*/
var $image_tint_color;
/**
* Applies a colored overlay on the image
*
* Value is an hexadecimal color, such as #FFFFFF
*
* To use with {@link image_overlay_opacity}
*
* Default value is null
*
* @access public
* @var string;
*/
var $image_overlay_color;
/**
* Sets the opacity for the colored overlay
*
* Value is a percentage, as an integer between 0 (transparent) and 100 (opaque)
*
* Unless used with {@link image_overlay_color}, this setting has no effect
*
* Default value is 50
*
* @access public
* @var integer
*/
var $image_overlay_opacity;
/**
* Inverts the color of an image
*
* Default value is FALSE
*
* @access public
* @var boolean;
*/
var $image_negative;
/**
* Turns the image into greyscale
*
* Default value is FALSE
*
* @access public
* @var boolean;
*/
var $image_greyscale;
/**
* Pixelate an image
*
* Value is integer, represents the block size
*
* Default value is null
*
* @access public
* @var integer;
*/
var $image_pixelate;
/**
* Applies an unsharp mask, with alpha transparency support
*
* Beware that this unsharp mask is quite resource-intensive
*
* Default value is FALSE
*
* @access public
* @var boolean;
*/
var $image_unsharp;
/**
* Sets the unsharp mask amount
*
* Value is an integer between 0 and 500, typically between 50 and 200
*
* Unless used with {@link image_unsharp}, this setting has no effect
*
* Default value is 80
*
* @access public
* @var integer
*/
var $image_unsharp_amount;
/**
* Sets the unsharp mask radius
*
* Value is an integer between 0 and 50, typically between 0.5 and 1
* It is not recommended to change it, the default works best
*
* Unless used with {@link image_unsharp}, this setting has no effect
*
* From PHP 5.1, imageconvolution is used, and this setting has no effect
*
* Default value is 0.5
*
* @access public