PageRenderTime 56ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 1ms

/protected/modules/fileManager/extensions/upload/Upload.php

https://bitbucket.org/graaaf/erso
PHP | 5139 lines | 2601 code | 321 blank | 2217 comment | 859 complexity | a717db24ca507be071cde3fd3fe22a25 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-3.0, LGPL-2.1, BSD-3-Clause, BSD-2-Clause

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. // +------------------------------------------------------------------------+
  3. // | class.upload.php |
  4. // +------------------------------------------------------------------------+
  5. // | Copyright (c) Colin Verot 2003-2010. All rights reserved. |
  6. // | Version 0.31 |
  7. // | Last modified 11/04/2011 |
  8. // | Email colin@verot.net |
  9. // | Web http://www.verot.net |
  10. // +------------------------------------------------------------------------+
  11. // | This program is free software; you can redistribute it and/or modify |
  12. // | it under the terms of the GNU General Public License version 2 as |
  13. // | published by the Free Software Foundation. |
  14. // | |
  15. // | This program is distributed in the hope that it will be useful, |
  16. // | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  17. // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
  18. // | GNU General Public License for more details. |
  19. // | |
  20. // | You should have received a copy of the GNU General Public License |
  21. // | along with this program; if not, write to the |
  22. // | Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
  23. // | Boston, MA 02111-1307 USA |
  24. // | |
  25. // | Please give credit on sites that use class.upload and submit changes |
  26. // | of the script so other people can use them as well. |
  27. // | This script is free to use, don't abuse. |
  28. // +------------------------------------------------------------------------+
  29. //
  30. /**
  31. * Class upload
  32. *
  33. * @version 0.31
  34. * @author Colin Verot <colin@verot.net>
  35. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  36. * @copyright Colin Verot
  37. * @package cmf
  38. * @subpackage external
  39. */
  40. /**
  41. * Class upload
  42. *
  43. * <b>What does it do?</b>
  44. *
  45. * It manages file uploads for you. In short, it manages the uploaded file,
  46. * and allows you to do whatever you want with the file, especially if it
  47. * is an image, and as many times as you want.
  48. *
  49. * It is the ideal class to quickly integrate file upload in your site.
  50. * If the file is an image, you can convert, resize, crop it in many ways.
  51. * You can also apply filters, add borders, text, watermarks, etc...
  52. * That's all you need for a gallery script for instance. Supported formats
  53. * are PNG, JPG, GIF and BMP.
  54. *
  55. * You can also use the class to work on local files, which is especially
  56. * useful to use the image manipulation features. The class also supports
  57. * Flash uploaders.
  58. *
  59. * The class works with PHP 4 and 5, and its error messages can
  60. * be localized at will.
  61. *
  62. * <b>How does it work?</b>
  63. *
  64. * You instanciate the class with the $_FILES['my_field'] array
  65. * where my_field is the field name from your upload form.
  66. * The class will check if the original file has been uploaded
  67. * to its temporary location (alternatively, you can instanciate
  68. * the class with a local filename).
  69. *
  70. * You can then set a number of processing variables to act on the file.
  71. * For instance, you can rename the file, and if it is an image,
  72. * convert and resize it in many ways.
  73. * You can also set what will the class do if the file already exists.
  74. *
  75. * Then you call the function {@link process} to actually perform the actions
  76. * according to the processing parameters you set above.
  77. * It will create new instances of the original file,
  78. * so the original file remains the same between each process.
  79. * The file will be manipulated, and copied to the given location.
  80. * The processing variables will be reset once it is done.
  81. *
  82. * You can repeat setting up a new set of processing variables,
  83. * and calling {@link process} again as many times as you want.
  84. * When you have finished, you can call {@link clean} to delete
  85. * the original uploaded file.
  86. *
  87. * If you don't set any processing parameters and call {@link process}
  88. * just after instanciating the class. The uploaded file will be simply
  89. * copied to the given location without any alteration or checks.
  90. *
  91. * Don't forget to add <i>enctype="multipart/form-data"</i> in your form
  92. * tag <form> if you want your form to upload the file.
  93. *
  94. * <b>How to use it?</b><br>
  95. * Create a simple HTML file, with a form such as:
  96. * <pre>
  97. * <form enctype="multipart/form-data" method="post" action="upload.php">
  98. * <input type="file" size="32" name="image_field" value="">
  99. * <input type="submit" name="Submit" value="upload">
  100. * </form>
  101. * </pre>
  102. * Create a file called upload.php:
  103. * <pre>
  104. * $handle = new Upload($_FILES['image_field']);
  105. * if ($handle->uploaded) {
  106. * $handle->file_new_name_body = 'image_resized';
  107. * $handle->image_resize = true;
  108. * $handle->image_x = 100;
  109. * $handle->image_ratio_y = true;
  110. * $handle->process('/home/user/files/');
  111. * if ($handle->processed) {
  112. * echo 'image resized';
  113. * $handle->clean();
  114. * } else {
  115. * echo 'error : ' . $handle->error;
  116. * }
  117. * }
  118. * </pre>
  119. *
  120. * <b>How to process local files?</b><br>
  121. * Use the class as following, the rest being the same as above:
  122. * <pre>
  123. * $handle = new Upload('/home/user/myfile.jpg');
  124. * </pre>
  125. *
  126. * <b>How to set the language?</b><br>
  127. * Instantiate the class with a second argument being the language code:
  128. * <pre>
  129. * $handle = new Upload($_FILES['image_field'], 'fr_FR');
  130. * $handle = new Upload('/home/user/myfile.jpg', 'fr_FR');
  131. * </pre>
  132. *
  133. * <b>How to output the resulting file or picture directly to the browser?</b><br>
  134. * Simply call {@link process}() without an argument (or with null as first argument):
  135. * <pre>
  136. * $handle = new Upload($_FILES['image_field']);
  137. * header('Content-type: ' . $handle->file_src_mime);
  138. * echo $handle->Process();
  139. * die();
  140. * </pre>
  141. * Or if you want to force the download of the file:
  142. * <pre>
  143. * $handle = new Upload($_FILES['image_field']);
  144. * header('Content-type: ' . $handle->file_src_mime);
  145. * header("Content-Disposition: attachment; filename=".rawurlencode($handle->file_src_name).";");
  146. * echo $handle->Process();
  147. * die();
  148. * </pre>
  149. *
  150. * <b>Processing parameters</b> (reset after each process)
  151. * <ul>
  152. * <li><b>{@link file_new_name_body}</b> replaces the name body (default: null)<br>
  153. * <pre>$handle->file_new_name_body = 'new name';</pre></li>
  154. * <li><b>{@link file_name_body_add}</b> appends to the name body (default: null)<br>
  155. * <pre>$handle->file_name_body_add = '_uploaded';</pre></li>
  156. * <li><b>{@link file_name_body_pre}</b> prepends to the name body (default: null)<br>
  157. * <pre>$handle->file_name_body_pre = 'thumb_';</pre></li>
  158. * <li><b>{@link file_new_name_ext}</b> replaces the file extension (default: null)<br>
  159. * <pre>$handle->file_new_name_ext = 'txt';</pre></li>
  160. * <li><b>{@link file_safe_name}</b> formats the filename (spaces changed to _) (default: true)<br>
  161. * <pre>$handle->file_safe_name = true;</pre></li>
  162. * <li><b>{@link file_force_extension}</b> forces an extension if there is't any (default: true)<br>
  163. * <pre>$handle->file_force_extension = true;</pre></li>
  164. * <li><b>{@link file_overwrite}</b> sets behaviour if file already exists (default: false)<br>
  165. * <pre>$handle->file_overwrite = true;</pre></li>
  166. * <li><b>{@link file_auto_rename}</b> automatically renames file if it already exists (default: true)<br>
  167. * <pre>$handle->file_auto_rename = true;</pre></li>
  168. * <li><b>{@link dir_auto_create}</b> automatically creates destination directory if missing (default: true)<br>
  169. * <pre>$handle->auto_create_dir = true;</pre></li>
  170. * <li><b>{@link dir_auto_chmod}</b> automatically attempts to chmod the destination directory if not writeable (default: true)<br>
  171. * <pre>$handle->dir_auto_chmod = true;</pre></li>
  172. * <li><b>{@link dir_chmod}</b> chmod used when creating directory or if directory not writeable (default: 0777)<br>
  173. * <pre>$handle->dir_chmod = 0777;</pre></li>
  174. * <li><b>{@link file_max_size}</b> sets maximum upload size (default: upload_max_filesize from php.ini)<br>
  175. * <pre>$handle->file_max_size = '1024'; // 1KB</pre></li>
  176. * <li><b>{@link mime_check}</b> sets if the class check the MIME against the {@link allowed} list (default: true)<br>
  177. * <pre>$handle->mime_check = true;</pre></li>
  178. * <li><b>{@link no_script}</b> sets if the class turns scripts into text files (default: true)<br>
  179. * <pre>$handle->no_script = false;</pre></li>
  180. * <li><b>{@link allowed}</b> array of allowed mime-types (or one string). wildcard accepted, as in image/* (default: check {@link Init})<br>
  181. * <pre>$handle->allowed = array('application/pdf','application/msword', 'image/*');</pre></li>
  182. * <li><b>{@link forbidden}</b> array of forbidden mime-types (or one string). wildcard accepted, as in image/* (default: check {@link Init})<br>
  183. * <pre>$handle->forbidden = array('application/*');</pre></li>
  184. * </ul>
  185. * <ul>
  186. * <li><b>{@link image_convert}</b> if set, image will be converted (possible values : ''|'png'|'jpeg'|'gif'|'bmp'; default: '')<br>
  187. * <pre>$handle->image_convert = 'jpg';</pre></li>
  188. * <li><b>{@link image_background_color}</b> if set, will forcibly fill transparent areas with the color, in hexadecimal (default: null)<br>
  189. * <pre>$handle->image_background_color = '#FF00FF';</pre></li>
  190. * <li><b>{@link image_default_color}</b> fallback color background color for non alpha-transparent output formats, such as JPEG or BMP, in hexadecimal (default: #FFFFFF)<br>
  191. * <pre>$handle->image_default_color = '#FF00FF';</pre></li>
  192. * <li><b>{@link jpeg_quality}</b> sets the compression quality for JPEG images (default: 85)<br>
  193. * <pre>$handle->jpeg_quality = 50;</pre></li>
  194. * <li><b>{@link jpeg_size}</b> if set to a size in bytes, will approximate {@link jpeg_quality} so the output image fits within the size (default: null)<br>
  195. * <pre>$handle->jpeg_size = 3072;</pre></li>
  196. * </ul>
  197. * The following eight settings can be used to invalidate an upload if the file is an image (note that <i>open_basedir</i> restrictions prevent the use of these settings)
  198. * <ul>
  199. * <li><b>{@link image_max_width}</b> if set to a dimension in pixels, the upload will be invalid if the image width is greater (default: null)<br>
  200. * <pre>$handle->image_max_width = 200;</pre></li>
  201. * <li><b>{@link image_max_height}</b> if set to a dimension in pixels, the upload will be invalid if the image height is greater (default: null)<br>
  202. * <pre>$handle->image_max_height = 100;</pre></li>
  203. * <li><b>{@link image_max_pixels}</b> if set to a number of pixels, the upload will be invalid if the image number of pixels is greater (default: null)<br>
  204. * <pre>$handle->image_max_pixels = 50000;</pre></li>
  205. * <li><b>{@link image_max_ratio}</b> if set to a aspect ratio (width/height), the upload will be invalid if the image apect ratio is greater (default: null)<br>
  206. * <pre>$handle->image_max_ratio = 1.5;</pre></li>
  207. * <li><b>{@link image_min_width}</b> if set to a dimension in pixels, the upload will be invalid if the image width is lower (default: null)<br>
  208. * <pre>$handle->image_min_width = 100;</pre></li>
  209. * <li><b>{@link image_min_height}</b> if set to a dimension in pixels, the upload will be invalid if the image height is lower (default: null)<br>
  210. * <pre>$handle->image_min_height = 500;</pre></li>
  211. * <li><b>{@link image_min_pixels}</b> if set to a number of pixels, the upload will be invalid if the image number of pixels is lower (default: null)<br>
  212. * <pre>$handle->image_min_pixels = 20000;</pre></li>
  213. * <li><b>{@link image_min_ratio}</b> if set to a aspect ratio (width/height), the upload will be invalid if the image apect ratio is lower (default: null)<br>
  214. * <pre>$handle->image_min_ratio = 0.5;</pre></li>
  215. * </ul>
  216. * <ul>
  217. * <li><b>{@link image_resize}</b> determines is an image will be resized (default: false)<br>
  218. * <pre>$handle->image_resize = true;</pre></li>
  219. * </ul>
  220. * The following variables are used only if {@link image_resize} == true
  221. * <ul>
  222. * <li><b>{@link image_x}</b> destination image width (default: 150)<br>
  223. * <pre>$handle->image_x = 100;</pre></li>
  224. * <li><b>{@link image_y}</b> destination image height (default: 150)<br>
  225. * <pre>$handle->image_y = 200;</pre></li>
  226. * </ul>
  227. * Use either one of the following
  228. * <ul>
  229. * <li><b>{@link image_ratio}</b> if true, resize image conserving the original sizes ratio, using {@link image_x} AND {@link image_y} as max sizes if true (default: false)<br>
  230. * <pre>$handle->image_ratio = true;</pre></li>
  231. * <li><b>{@link image_ratio_crop}</b> if true, resize image conserving the original sizes ratio, using {@link image_x} AND {@link image_y} as max sizes, and cropping excedent to fill the space. setting can also be a string, with one or more from 'TBLR', indicating which side of the image will be kept while cropping (default: false)<br>
  232. * <pre>$handle->image_ratio_crop = true;</pre></li>
  233. * <li><b>{@link image_ratio_fill}</b> if true, resize image conserving the original sizes ratio, using {@link image_x} AND {@link image_y} as max sizes, fitting the image in the space and coloring the remaining space. setting can also be a string, with one or more from 'TBLR', indicating which side of the space the image will be in (default: false)<br>
  234. * <pre>$handle->image_ratio_fill = true;</pre></li>
  235. * <li><b>{@link image_ratio_no_zoom_in}</b> same as {@link image_ratio}, but won't resize if the source image is smaller than {@link image_x} x {@link image_y} (default: false)<br>
  236. * <pre>$handle->image_ratio_no_zoom_in = true;</pre></li>
  237. * <li><b>{@link image_ratio_no_zoom_out}</b> same as {@link image_ratio}, but won't resize if the source image is bigger than {@link image_x} x {@link image_y} (default: false)<br>
  238. * <pre>$handle->image_ratio_no_zoom_out = true;</pre></li>
  239. * <li><b>{@link image_ratio_x}</b> if true, resize image, calculating {@link image_x} from {@link image_y} and conserving the original sizes ratio (default: false)<br>
  240. * <pre>$handle->image_ratio_x = true;</pre></li>
  241. * <li><b>{@link image_ratio_y}</b> if true, resize image, calculating {@link image_y} from {@link image_x} and conserving the original sizes ratio (default: false)<br>
  242. * <pre>$handle->image_ratio_y = true;</pre></li>
  243. * <li><b>{@link image_ratio_pixels}</b> if set to a long integer, resize image, calculating {@link image_y} and {@link image_x} to match a the number of pixels (default: false)<br>
  244. * <pre>$handle->image_ratio_pixels = 25000;</pre></li>
  245. * </ul>
  246. * The following image manipulations require GD2+
  247. * <ul>
  248. * <li><b>{@link image_brightness}</b> if set, corrects the brightness. value between -127 and 127 (default: null)<br>
  249. * <pre>$handle->image_brightness = 40;</pre></li>
  250. * <li><b>{@link image_contrast}</b> if set, corrects the contrast. value between -127 and 127 (default: null)<br>
  251. * <pre>$handle->image_contrast = 50;</pre></li>
  252. * <li><b>{@link image_opacity}</b> if set, changes the image opacity. value between 0 and 100 (default: null)<br>
  253. * <pre>$handle->image_opacity = 50;</pre></li>
  254. * <li><b>{@link image_tint_color}</b> if set, will tint the image with a color, value as hexadecimal #FFFFFF (default: null)<br>
  255. * <pre>$handle->image_tint_color = '#FF0000';</pre></li>
  256. * <li><b>{@link image_overlay_color}</b> if set, will add a colored overlay, value as hexadecimal #FFFFFF (default: null)<br>
  257. * <pre>$handle->image_overlay_color = '#FF0000';</pre></li>
  258. * <li><b>{@link image_overlay_opacity}</b> used when {@link image_overlay_color} is set, determines the opacity (default: 50)<br>
  259. * <pre>$handle->image_overlay_opacity = 20;</pre></li>
  260. * <li><b>{@link image_negative}</b> inverts the colors in the image (default: false)<br>
  261. * <pre>$handle->image_negative = true;</pre></li>
  262. * <li><b>{@link image_greyscale}</b> transforms an image into greyscale (default: false)<br>
  263. * <pre>$handle->image_greyscale = true;</pre></li>
  264. * <li><b>{@link image_threshold}</b> applies a threshold filter. value between -127 and 127 (default: null)<br>
  265. * <pre>$handle->image_threshold = 20;</pre></li>
  266. * <li><b>{@link image_unsharp}</b> applies an unsharp mask, with alpha transparency support (default: false)<br>
  267. * <pre>$handle->image_unsharp = true;</pre></li>
  268. * <li><b>{@link image_unsharp_amount}</b> unsharp mask amount, typically 50 - 200 (default: 80)<br>
  269. * <pre>$handle->image_unsharp_amount = 120;</pre></li>
  270. * <li><b>{@link image_unsharp_radius}</b> unsharp mask radius, typically 0.5 - 1 (default: 0.5)<br>
  271. * <pre>$handle->image_unsharp_radius = 0.8;</pre></li>
  272. * <li><b>{@link image_unsharp_threshold}</b> unsharp mask threshold, typically 0 - 5 (default: 1)<br>
  273. * <pre>$handle->image_unsharp_threshold = 0;</pre></li>
  274. * </ul>
  275. * <ul>
  276. * <li><b>{@link image_text}</b> creates a text label on the image, value is a string, with eventual replacement tokens (default: null)<br>
  277. * <pre>$handle->image_text = 'test';</pre></li>
  278. * <li><b>{@link image_text_direction}</b> text label direction, either 'h' horizontal or 'v' vertical (default: 'h')<br>
  279. * <pre>$handle->image_text_direction = 'v';</pre></li>
  280. * <li><b>{@link image_text_color}</b> text color for the text label, in hexadecimal (default: #FFFFFF)<br>
  281. * <pre>$handle->image_text_color = '#FF0000';</pre></li>
  282. * <li><b>{@link image_text_opacity}</b> text opacity on the text label, integer between 0 and 100 (default: 100)<br>
  283. * <pre>$handle->image_text_opacity = 50;</pre></li>
  284. * <li><b>{@link image_text_background}</b> text label background color, in hexadecimal (default: null)<br>
  285. * <pre>$handle->image_text_background = '#FFFFFF';</pre></li>
  286. * <li><b>{@link image_text_background_opacity}</b> text label background opacity, integer between 0 and 100 (default: 100)<br>
  287. * <pre>$handle->image_text_background_opacity = 50;</pre></li>
  288. * <li><b>{@link image_text_font}</b> built-in font for the text label, from 1 to 5. 1 is the smallest (default: 5)<br>
  289. * <pre>$handle->image_text_font = 4;</pre></li>
  290. * <li><b>{@link image_text_x}</b> absolute text label position, in pixels from the left border. can be negative (default: null)<br>
  291. * <pre>$handle->image_text_x = 5;</pre></li>
  292. * <li><b>{@link image_text_y}</b> absolute text label position, in pixels from the top border. can be negative (default: null)<br>
  293. * <pre>$handle->image_text_y = 5;</pre></li>
  294. * <li><b>{@link image_text_position}</b> text label position withing the image, a combination of one or two from 'TBLR': top, bottom, left, right (default: null)<br>
  295. * <pre>$handle->image_text_position = 'LR';</pre></li>
  296. * <li><b>{@link image_text_padding}</b> text label padding, in pixels. can be overridden by {@link image_text_padding_x} and {@link image_text_padding_y} (default: 0)<br>
  297. * <pre>$handle->image_text_padding = 5;</pre></li>
  298. * <li><b>{@link image_text_padding_x}</b> text label horizontal padding (default: null)<br>
  299. * <pre>$handle->image_text_padding_x = 2;</pre></li>
  300. * <li><b>{@link image_text_padding_y}</b> text label vertical padding (default: null)<br>
  301. * <pre>$handle->image_text_padding_y = 10;</pre></li>
  302. * <li><b>{@link image_text_alignment}</b> text alignment when text has multiple lines, either 'L', 'C' or 'R' (default: 'C')<br>
  303. * <pre>$handle->image_text_alignment = 'R';</pre></li>
  304. * <li><b>{@link image_text_line_spacing}</b> space between lines in pixels, when text has multiple lines (default: 0)<br>
  305. * <pre>$handle->image_text_line_spacing = 3;</pre></li>
  306. * </ul>
  307. * <ul>
  308. * <li><b>{@link image_flip}</b> flips image, wither 'h' horizontal or 'v' vertical (default: null)<br>
  309. * <pre>$handle->image_flip = 'h';</pre></li>
  310. * <li><b>{@link image_rotate}</b> rotates image. possible values are 90, 180 and 270 (default: null)<br>
  311. * <pre>$handle->image_rotate = 90;</pre></li>
  312. * <li><b>{@link image_crop}</b> crops image. accepts 4, 2 or 1 values as 'T R B L' or 'TB LR' or 'TBLR'. dimension can be 20, or 20px or 20% (default: null)<br>
  313. * <pre>$handle->image_crop = array(50,40,30,20); OR '-20 20%'...</pre></li>
  314. * <li><b>{@link image_precrop}</b> crops image, before an eventual resizing. accepts 4, 2 or 1 values as 'T R B L' or 'TB LR' or 'TBLR'. dimension can be 20, or 20px or 20% (default: null)<br>
  315. * <pre>$handle->image_precrop = array(50,40,30,20); OR '-20 20%'...</pre></li>
  316. * </ul>
  317. * <ul>
  318. * <li><b>{@link image_bevel}</b> adds a bevel border to the image. value is thickness in pixels (default: null)<br>
  319. * <pre>$handle->image_bevel = 20;</pre></li>
  320. * <li><b>{@link image_bevel_color1}</b> top and left bevel color, in hexadecimal (default: #FFFFFF)<br>
  321. * <pre>$handle->image_bevel_color1 = '#FFFFFF';</pre></li>
  322. * <li><b>{@link image_bevel_color2}</b> bottom and right bevel color, in hexadecimal (default: #000000)<br>
  323. * <pre>$handle->image_bevel_color2 = '#000000';</pre></li>
  324. * <li><b>{@link image_border}</b> adds a unicolor border to the image. accepts 4, 2 or 1 values as 'T R B L' or 'TB LR' or 'TBLR'. dimension can be 20, or 20px or 20% (default: null)<br>
  325. * <pre>$handle->image_border = '3px'; OR '-20 20%' OR array(3,2)...</pre></li>
  326. * <li><b>{@link image_border_color}</b> border color, in hexadecimal (default: #FFFFFF)<br>
  327. * <pre>$handle->image_border_color = '#FFFFFF';</pre></li>
  328. * <li><b>{@link image_border_opacity}</b> border opacity, integer between 0 and 100 (default: 100)<br>
  329. * <pre>$handle->image_border_opacity = 50;</pre></li>
  330. * <li><b>{@link image_border_transparent}</b> adds a fading-to-transparent border to the image. accepts 4, 2 or 1 values as 'T R B L' or 'TB LR' or 'TBLR'. dimension can be 20, or 20px or 20% (default: null)<br>
  331. * <pre>$handle->image_border_transparent = '3px'; OR '-20 20%' OR array(3,2)...</pre></li>
  332. * <li><b>{@link image_frame}</b> type of frame: 1=flat 2=crossed (default: null)<br>
  333. * <pre>$handle->image_frame = 2;</pre></li>
  334. * <li><b>{@link image_frame_colors}</b> list of hex colors, in an array or a space separated string (default: '#FFFFFF #999999 #666666 #000000')<br>
  335. * <pre>$handle->image_frame_colors = array('#999999', '#FF0000', '#666666', '#333333', '#000000');</pre></li>
  336. * <li><b>{@link image_frame_opacity}</b> frame opacity, integer between 0 and 100 (default: 100)<br>
  337. * <pre>$handle->image_frame_opacity = 50;</pre></li>
  338. * </ul>
  339. * <ul>
  340. * <li><b>{@link image_watermark}</b> adds a watermark on the image, value is a local filename. accepted files are GIF, JPG, BMP, PNG and PNG alpha (default: null)<br>
  341. * <pre>$handle->image_watermark = 'watermark.png';</pre></li>
  342. * <li><b>{@link image_watermark_x}</b> absolute watermark position, in pixels from the left border. can be negative (default: null)<br>
  343. * <pre>$handle->image_watermark_x = 5;</pre></li>
  344. * <li><b>{@link image_watermark_y}</b> absolute watermark position, in pixels from the top border. can be negative (default: null)<br>
  345. * <pre>$handle->image_watermark_y = 5;</pre></li>
  346. * <li><b>{@link image_watermark_position}</b> watermark position withing the image, a combination of one or two from 'TBLR': top, bottom, left, right (default: null)<br>
  347. * <pre>$handle->image_watermark_position = 'LR';</pre></li>
  348. * <li><b>{@link image_watermark_no_zoom_in}</b> prevents the watermark to be resized up if it is smaller than the image (default: true)<br>
  349. * <pre>$handle->image_watermark_no_zoom_in = false;</pre></li>
  350. * <li><b>{@link image_watermark_no_zoom_out}</b> prevents the watermark to be resized down if it is bigger than the image (default: false)<br>
  351. * <pre>$handle->image_watermark_no_zoom_out = true;</pre></li>
  352. * </ul>
  353. * <ul>
  354. * <li><b>{@link image_reflection_height}</b> if set, a reflection will be added. Format is either in pixels or percentage, such as 40, '40', '40px' or '40%' (default: null)<br>
  355. * <pre>$handle->image_reflection_height = '25%';</pre></li>
  356. * <li><b>{@link image_reflection_space}</b> space in pixels between the source image and the reflection, can be negative (default: null)<br>
  357. * <pre>$handle->image_reflection_space = 3;</pre></li>
  358. * <li><b>{@link image_reflection_color}</b> reflection background color, in hexadecimal. Now deprecated in favor of {@link image_default_color} (default: #FFFFFF)<br>
  359. * <pre>$handle->image_default_color = '#000000';</pre></li>
  360. * <li><b>{@link image_reflection_opacity}</b> opacity level at which the reflection starts, integer between 0 and 100 (default: 60)<br>
  361. * <pre>$handle->image_reflection_opacity = 60;</pre></li>
  362. * </ul>
  363. *
  364. * <b>Values that can be read before calling {@link process}()</b>
  365. * <ul>
  366. * <li><b>{@link file_src_name}</b> Source file name</li>
  367. * <li><b>{@link file_src_name_body}</b> Source file name body</li>
  368. * <li><b>{@link file_src_name_ext}</b> Source file extension</li>
  369. * <li><b>{@link file_src_pathname}</b> Source file complete path and name</li>
  370. * <li><b>{@link file_src_mime}</b> Source file mime type</li>
  371. * <li><b>{@link file_src_size}</b> Source file size in bytes</li>
  372. * <li><b>{@link file_src_error}</b> Upload error code</li>
  373. * <li><b>{@link file_is_image}</b> Boolean flag, true if the file is a supported image type</li>
  374. * </ul>
  375. * If the file is a supported image type (and <i>open_basedir</i> restrictions allow it)
  376. * <ul>
  377. * <li><b>{@link image_src_x}</b> Source file width in pixels</li>
  378. * <li><b>{@link image_src_y}</b> Source file height in pixels</li>
  379. * <li><b>{@link image_src_pixels}</b> Source file number of pixels</li>
  380. * <li><b>{@link image_src_type}</b> Source file type (png, jpg, gif or bmp)</li>
  381. * <li><b>{@link image_src_bits}</b> Source file color depth</li>
  382. * </ul>
  383. *
  384. * <b>Values that can be read after calling {@link process}()</b>
  385. * <ul>
  386. * <li><b>{@link file_dst_path}</b> Destination file path</li>
  387. * <li><b>{@link file_dst_name_body}</b> Destination file name body</li>
  388. * <li><b>{@link file_dst_name_ext}</b> Destination file extension</li>
  389. * <li><b>{@link file_dst_name}</b> Destination file name</li>
  390. * <li><b>{@link file_dst_pathname}</b> Destination file complete path and name</li>
  391. * </ul>
  392. * If the file is a supported image type
  393. * <ul>
  394. * <li><b>{@link image_dst_x}</b> Destination file width</li>
  395. * <li><b>{@link image_dst_y}</b> Destination file height</li>
  396. * <li><b>{@link image_convert}</b> Destination file format</li>
  397. * </ul>
  398. *
  399. * <b>Requirements</b>
  400. *
  401. * Most of the image operations require GD. GD2 is greatly recommended
  402. *
  403. * The class is compatible with PHP 4.3+, and compatible with PHP5
  404. *
  405. * <b>Changelog</b>
  406. * <ul>
  407. * <li><b>v 0.31</b> 11/04/2011<br>
  408. * - added application/x-rar MIME type<br>
  409. * - make sure exec() and ini_get_all()function are not disabled if we want to use them<br>
  410. * - make sure that we don't divide by zero when calculating JPEG size<br>
  411. * - {@link allowed} and {@link forbidden} can now accept strings<br>
  412. * - try to guess the file extension from the MIME type if there is no file extension<br>
  413. * - better class properties when changing the file extension<br>
  414. * - added {@link file_force_extension} to allow extension-less files if needed<br>
  415. * - better file safe conversion of the filename<br>
  416. * - allow shorthand byte values, such as 1K, 2M, 3G for {@link file_max_size} and {@link jpeg_size}<br>
  417. * - added {@link image_opacity} to change picture opacity<br>
  418. * - added {@link image_border_opacity} to allow semi-transparent borders<br>
  419. * - added {@link image_frame_opacity} to allow semi-transparent frames<br>
  420. * - added {@link image_border_transparent} to allow borders fading to transparent<br>
  421. * - duplicated {@link image_overlay_percent} into {@link image_overlay_opacity}<br>
  422. * - duplicated {@link image_text_percent} into {@link image_text_opacity}<br>
  423. * - duplicated {@link image_text_background_percent} into {@link image_text_background_opacity}</li>
  424. * <li><b>v 0.30</b> 05/09/2010<br>
  425. * - implemented an unsharp mask, with alpha transparency support, activated if {@link image_unsharp} is true. added {@link image_unsharp_amount}, {@link image_unsharp_radius}, and {@link image_unsharp_threshold}<br>
  426. * - added text/rtf MIME type, and no_script exception<br>
  427. * - corrected bug when {@link no_script} is activated and several process() are called<br>
  428. * - better error handling for finfo<br>
  429. * - display upload_max_filesize information from php.ini in the log<br>
  430. * - automatic extension for extension-less images<br>
  431. * - fixed {@link image_ratio_fill} top and left filling<br>
  432. * - fixed alphablending issue when applying a transparent PNG watermark on a transparent PNG<br>
  433. * - added {@link image_watermark_no_zoom_in} and {@link image_watermark_no_zoom_out} to allow the watermark to be resized down (or up) to fit in the image. By default, the watermark may be resized down, but not up.</li>
  434. * <li><b>v 0.29</b> 03/02/2010<br>
  435. * - added protection against malicious images<br>
  436. * - added zip and torrent MIME type<br>
  437. * - replaced split() with explode()<br>
  438. * - initialise image_dst_x/y with image_src_x/y<br>
  439. * - removed {@link mime_fileinfo}, {@link mime_file}, {@link mime_magic} and {@link mime_getimagesize} from the docs since they are used before {@link process}<br>
  440. * - added more extensions and MIME types<br>
  441. * - improved MIME type validation<br>
  442. * - improved logging</li>
  443. * <li><b>v 0.28</b> 10/08/2009<br>
  444. * - replaced ereg functions to be compatible with PHP 5.3<br>
  445. * - added flv MIME type<br>
  446. * - improved MIME type detection<br>
  447. * - added {@link file_name_body_pre} to prepend a string to the file name<br>
  448. * - added {@link mime_fileinfo}, {@link mime_file}, {@link mime_magic} and {@link mime_getimagesize} so that it is possible to deactivate some MIME type checking method<br>
  449. * - use exec() rather than shell_exec(), to play better with safe mode <br>
  450. * - added some error messages<br>
  451. * - fix bug when checking on conditions, {@link processed} wasn't propagated properly</li>
  452. * <li><b>v 0.27</b> 14/05/2009<br>
  453. * - look for the language files directory from __FILE__<br>
  454. * - deactivate {@link file_auto_rename} if {@link file_overwrite} is set<br>
  455. * - improved transparency replacement for true color images<br>
  456. * - fixed calls to newer version of UNIX file utility<br>
  457. * - fixed error when using PECL Fileinfo extension in SAFE MODE, and when using the finfo class<br>
  458. * - added {@link image_precrop} to crop the image before an eventual resizing</li>
  459. * <li><b>v 0.26</b> 13/11/2008<br>
  460. * - rewrote conversion from palette to true color to handle transparency better<br>
  461. * - fixed imagecopymergealpha() when the overlayed image is of wrong dimensions<br>
  462. * - fixed imagecreatenew() when the image to create have less than 1 pixels width or height<br>
  463. * - rewrote MIME type detection to be more secure and not rely on browser information; now using Fileinfo PECL extension, UNIX file() command, MIME magic, and getimagesize(), in that order<br>
  464. * - added support for Flash uploaders<br>
  465. * - some bug fixing and error handling</li>
  466. * <li><b>v 0.25</b> 17/11/2007<br>
  467. * - added translation files and mechanism to instantiate the class with a language different from English<br>
  468. * - added {@link forbidden} to set an array of forbidden MIME types<br>
  469. * - implemented support for simple wildcards in {@link allowed} and {@link forbidden}, such as image/*<br>
  470. * - preset the file extension to the desired conversion format when converting an image<br>
  471. * - added read and write support for BMP images<br>
  472. * - added a flag {@link file_is_image} to determine if the file is a supported image type<br>
  473. * - the class now provides some information about the image, before calling {@link process}(). Available are {@link image_src_x}, {@link image_src_y} and the newly introduced {@link image_src_bits}, {@link image_src_pixels} and {@link image_src_type}. Note that this will not work if <i>open_basedir</i> restrictions are in place<br>
  474. * - improved logging; now provides useful system information<br>
  475. * - added some more pre-processing checks for files that are images: {@link image_max_width}, {@link image_max_height}, {@link image_max_pixels}, {@link image_max_ratio}, {@link image_min_width}, {@link image_min_height}, {@link image_min_pixels} and {@link image_min_ratio}<br>
  476. * - added {@link image_ratio_pixels} to resize an image to a number of pixels, keeping aspect ratio<br>
  477. * - added {@link image_is_palette} and {@link image_is_transparent} and {@link image_transparent_color} for GIF images<br>
  478. * - added {@link image_default_color} to define a fallback color for non alpha-transparent output formats, such as JPEG or BMP<br>
  479. * - changed {@link image_background_color}, which now forces transparent areas to be painted<br>
  480. * - improved reflections and color overlays so that it works with alpha transparent images<br>
  481. * - {@link image_reflection_color} is now deprecated in favour of {@link image_default_color}<br />
  482. * - transparent PNGs are now processed in true color, and fully preserving the alpha channel when doing merges<br>
  483. * - transparent GIFs are now automatically detected. {@link preserve_transparency} is deprecated<br>
  484. * - transparent true color images can be saved as GIF while retaining transparency, semi transparent areas being merged with {@link image_default_color}<br>
  485. * - transparent true color images can be saved as JPG/BMP with the semi transparent areas being merged with {@link image_default_color}<br>
  486. * - fixed conversion of images to true color<br>
  487. * - the class can now output the uploaded files content as the return value of process() if the function is called with an empty or null argumenti, or no argument</li>
  488. * <li><b>v 0.24</b> 25/05/2007<br>
  489. * - added {@link image_background_color}, to set the default background color of an image<br>
  490. * - added possibility of using replacement tokens in text labels<br>
  491. * - changed default JPEG quality to 85<br>
  492. * - fixed a small bug when using greyscale filter and associated filters<br>
  493. * - added {@link image_ratio_fill} in order to fit an image within some dimensions and color the remaining space. Very similar to {@link image_ratio_crop}<br>
  494. * - improved the recursive creation of directories<br>
  495. * - the class now converts palette based images to true colors before doing graphic manipulations</li>
  496. * <li><b>v 0.23</b> 23/12/2006<br>
  497. * - fixed a bug when processing more than once the same uploaded file. If there is an open_basedir restriction, the class now creates a temporary file for the first call to process(). This file will be used for subsequent processes, and will be deleted upon calling clean()</li>
  498. * <li><b>v 0.22</b> 16/12/2006<br>
  499. * - added automatic creation of a temporary file if the upload directory is not within open_basedir<br>
  500. * - fixed a bug which was preventing to work on a local file by overwriting it with its processed copy<br>
  501. * - added MIME types video/x-ms-wmv and image/x-png and fixed PNG support for IE weird MIME types<br>
  502. * - modified {@link image_ratio_crop} so it can accept one or more from string 'TBLR', determining which side of the image is kept while cropping<br>
  503. * - added support for multiple lines in the text, using "\n" as a line break<br>
  504. * - added {@link image_text_line_spacing} which allow to set the space between several lines of text<br>
  505. * - added {@link image_text_alignment} which allow to set the alignment when text has several lines<br>
  506. * - {@link image_text_font} can now be set to the path of a GDF font to load external fonts<br>
  507. * - added {@link image_reflection_height} to create a reflection of the source image, which height is in pixels or percentage<br>
  508. * - added {@link image_reflection_space} to set the space in pixels between the source image and the reflection<br>
  509. * - added {@link image_reflection_color} to set the reflection background color<br>
  510. * - added {@link image_reflection_opacity} to set the initial level of opacity of the reflection</li>
  511. * <li><b>v 0.21</b> 30/09/2006<br>
  512. * - added {@link image_ratio_crop} which resizes within {@link image_x} and {@link image_y}, keeping ratio, but filling the space by cropping excedent of image<br>
  513. * - added {@link mime_check}, which default is true, to set checks against {@link allowed} MIME list<br>
  514. * - if MIME is empty, the class now triggers an error<br>
  515. * - color #000000 is OK for {@link image_text_color}, and related text transparency bug fixed<br>
  516. * - {@link gd_version}() now uses gd_info(), or else phpinfo()<br>
  517. * - fixed path issue when the destination path has no trailing slash on Windows systems <br>
  518. * - removed inline functions to be fully PHP5 compatible </li>
  519. * <li><b>v 0.20</b> 11/08/2006<br>
  520. * - added some more error checking and messages (GD presence, permissions...)<br>
  521. * - fix when uploading files without extension<br>
  522. * - changed values for {@link image_brightness} and {@link image_contrast} to be between -127 and 127<br>
  523. * - added {@link dir_auto_create} to automatically and recursively create destination directory if missing.<br>
  524. * - added {@link dir_auto_chmod} to automatically chmod the destination directory if not writeable.<br>
  525. * - added {@link dir_chmod} to set the default chmod to use.<br>
  526. * - added {@link image_crop} to crop images<br>
  527. * - added {@link image_negative} to invert the colors on the image<br>
  528. * - added {@link image_greyscale} to turn the image into greyscale<br>
  529. * - added {@link image_threshold} to apply a threshold filter on the image<br>
  530. * - added {@link image_bevel}, {@link image_bevel_color1} and {@link image_bevel_color2} to add a bevel border<br>
  531. * - added {@link image_border} and {@link image_border_color} to add a single color border<br>
  532. * - added {@link image_frame} and {@link image_frame_colors} to add a multicolored frame</li>
  533. * <li><b>v 0.19</b> 29/03/2006<br>
  534. * - class is now compatible i18n (thanks Sylwester).<br>
  535. * - the class can mow manipulate local files, not only uploaded files (instanciate the class with a local filename).<br>
  536. * - {@link file_safe_name} has been improved a bit.<br>
  537. * - added {@link image_brightness}, {@link image_contrast}, {@link image_tint_color}, {@link image_overlay_color} and {@link image_overlay_percent} to do color manipulation on the images.<br>
  538. * - added {@link image_text} and all derivated settings to add a text label on the image.<br>
  539. * - added {@link image_watermark} and all derivated settings to add a watermark image on the image.<br>
  540. * - added {@link image_flip} and {@link image_rotate} for more image manipulations<br>
  541. * - added {@link jpeg_size} to calculate the JPG compression quality in order to fit within one filesize.</li>
  542. * <li><b>v 0.18</b> 02/02/2006<br>
  543. * - added {@link no_script} to turn dangerous scripts into text files.<br>
  544. * - added {@link mime_magic_check} to set the class to use mime_magic.<br>
  545. * - added {@link preserve_transparency} *experimental*. Thanks Gregor.<br>
  546. * - fixed size and mime checking, wasn't working :/ Thanks Willem.<br>
  547. * - fixed memory leak when resizing images.<br>
  548. * - when resizing, it is not necessary anymore to set {@link image_convert}.<br>
  549. * - il is now possible to simply convert an image, with no resizing.<br>
  550. * - sets the default {@link file_max_size} to upload_max_filesize from php.ini. Thanks Edward</li>
  551. * <li><b>v 0.17</b> 28/05/2005<br>
  552. * - the class can be used with any version of GD.<br>
  553. * - added security check on the file with a list of mime-types.<br>
  554. * - changed the license to GPL v2 only</li>
  555. * <li><b>v 0.16</b> 19/05/2005<br>
  556. * - added {@link file_auto_rename} automatic file renaming if the same filename already exists.<br>
  557. * - added {@link file_safe_name} safe formatting of the filename (spaces to _underscores so far).<br>
  558. * - added some more error reporting to avoid crash if GD is not present</li>
  559. * <li><b>v 0.15</b> 16/04/2005<br>
  560. * - added JPEG compression quality setting. Thanks Vad</li>
  561. * <li><b>v 0.14</b> 14/03/2005<br>
  562. * - reworked the class file to allow parsing with phpDocumentor</li>
  563. * <li><b>v 0.13</b> 07/03/2005<br>
  564. * - fixed a bug with {@link image_ratio}. Thanks Justin.<br>
  565. * - added {@link image_ratio_no_zoom_in} and {@link image_ratio_no_zoom_out} </li>
  566. * <li><b>v 0.12</b> 21/01/2005<br>
  567. * - added {@link image_ratio} to resize within max values, keeping image ratio</li>
  568. * <li><b>v 0.11</b> 22/08/2003<br>
  569. * - update for GD2 (changed imageresized() into imagecopyresampled() and imagecreate() into imagecreatetruecolor())</li>
  570. * </ul>
  571. *
  572. * @package cmf
  573. * @subpackage external
  574. */
  575. class Upload {
  576. /**
  577. * Class version
  578. *
  579. * @access public
  580. * @var string
  581. */
  582. var $version;
  583. /**
  584. * Uploaded file name
  585. *
  586. * @access public
  587. * @var string
  588. */
  589. var $file_src_name;
  590. /**
  591. * Uploaded file name body (i.e. without extension)
  592. *
  593. * @access public
  594. * @var string
  595. */
  596. var $file_src_name_body;
  597. /**
  598. * Uploaded file name extension
  599. *
  600. * @access public
  601. * @var string
  602. */
  603. var $file_src_name_ext;
  604. /**
  605. * Uploaded file MIME type
  606. *
  607. * @access public
  608. * @var string
  609. */
  610. var $file_src_mime;
  611. /**
  612. * Uploaded file size, in bytes
  613. *
  614. * @access public
  615. * @var double
  616. */
  617. var $file_src_size;
  618. /**
  619. * Holds eventual PHP error code from $_FILES
  620. *
  621. * @access public
  622. * @var string
  623. */
  624. var $file_src_error;
  625. /**
  626. * Uloaded file name, including server path
  627. *
  628. * @access public
  629. * @var string
  630. */
  631. var $file_src_pathname;
  632. /**
  633. * Uloaded file name temporary copy
  634. *
  635. * @access private
  636. * @var string
  637. */
  638. var $file_src_temp;
  639. /**
  640. * Destination file name
  641. *
  642. * @access public
  643. * @var string
  644. */
  645. var $file_dst_path;
  646. /**
  647. * Destination file name
  648. *
  649. * @access public
  650. * @var string
  651. */
  652. var $file_dst_name;
  653. /**
  654. * Destination file name body (i.e. without extension)
  655. *
  656. * @access public
  657. * @var string
  658. */
  659. var $file_dst_name_body;
  660. /**
  661. * Destination file extension
  662. *
  663. * @access public
  664. * @var string
  665. */
  666. var $file_dst_name_ext;
  667. /**
  668. * Destination file name, including path
  669. *
  670. * @access public
  671. * @var string
  672. */
  673. var $file_dst_pathname;
  674. /**
  675. * Source image width
  676. *
  677. * @access public
  678. * @var integer
  679. */
  680. var $image_src_x;
  681. /**
  682. * Source image height
  683. *
  684. * @access public
  685. * @var integer
  686. */
  687. var $image_src_y;
  688. /**
  689. * Source image color depth
  690. *
  691. * @access public
  692. * @var integer
  693. */
  694. var $image_src_bits;
  695. /**
  696. * Number of pixels
  697. *
  698. * @access public
  699. * @var long
  700. */
  701. var $image_src_pixels;
  702. /**
  703. * Type of image (png, gif, jpg or bmp)
  704. *
  705. * @access public
  706. * @var string
  707. */
  708. var $image_src_type;
  709. /**
  710. * Destination image width
  711. *
  712. * @access public
  713. * @var integer
  714. */
  715. var $image_dst_x;
  716. /**
  717. * Destination image height
  718. *
  719. * @access public
  720. * @var integer
  721. */
  722. var $image_dst_y;
  723. /**
  724. * Supported image formats
  725. *
  726. * @access private
  727. * @var array
  728. */
  729. var $image_supported;
  730. /**
  731. * Flag to determine if the source file is an image
  732. *
  733. * @access public
  734. * @var boolean
  735. */
  736. var $file_is_image;
  737. /**
  738. * Flag set after instanciating the class
  739. *
  740. * Indicates if the file has been uploaded properly
  741. *
  742. * @access public
  743. * @var bool
  744. */
  745. var $uploaded;
  746. /**
  747. * Flag stopping PHP upload checks
  748. *
  749. * Indicates whether we instanciated the class with a filename, in which case
  750. * we will not check on the validity of the PHP *upload*
  751. *
  752. * This flag is automatically set to true when working on a local file
  753. *
  754. * Warning: for uploads, this flag MUST be set to false for security reason
  755. *
  756. * @access public
  757. * @var bool
  758. */
  759. var $no_upload_check;
  760. /**
  761. * Flag set after calling a process
  762. *
  763. * Indicates if the processing, and copy of the resulting file went OK
  764. *
  765. * @access public
  766. * @var bool
  767. */
  768. var $processed;
  769. /**
  770. * Holds eventual error message in plain english
  771. *
  772. * @access public
  773. * @var string
  774. */
  775. var $error;
  776. /**
  777. * Holds an HTML formatted log
  778. *
  779. * @access public
  780. * @var string
  781. */
  782. var $log;
  783. // overiddable processing variables
  784. /**
  785. * Set this variable to replace the name body (i.e. without extension)
  786. *
  787. * @access public
  788. * @var string
  789. */
  790. var $file_new_name_body;
  791. /**
  792. * Set this variable to append a string to the file name body
  793. *
  794. * @access public
  795. * @var string
  796. */
  797. var $file_name_body_add;
  798. /**
  799. * Set this variable to prepend a string to the file name body
  800. *
  801. * @access public
  802. * @var string
  803. */
  804. var $file_name_body_pre;
  805. /**
  806. * Set this variable to change the file extension
  807. *
  808. * @access public
  809. * @var string
  810. */
  811. var $file_new_name_ext;
  812. /**
  813. * Set this variable to format the filename (spaces changed to _)
  814. *
  815. * @access public
  816. * @var boolean
  817. */
  818. var $file_safe_name;
  819. /**
  820. * Forces an extension if the source file doesn't have one
  821. *
  822. * If the file is an image, then the correct extension will be added
  823. * Otherwise, a .txt extension will be chosen
  824. *
  825. * @access public
  826. * @var boolean
  827. */
  828. var $file_force_extension;
  829. /**
  830. * Set this variable to false if you don't want to check the MIME against the allowed list
  831. *
  832. * This variable is set to true by default for security reason
  833. *
  834. * @access public
  835. * @var boolean
  836. */
  837. var $mime_check;
  838. /**
  839. * Set this variable to false in the init() function if you don't want to check the MIME
  840. * with Fileinfo PECL extension. On some systems, Fileinfo is known to be buggy, and you
  841. * may want to deactivate it in the class code directly.
  842. *
  843. * You can also set it with the path of the magic database file.
  844. * If set to true, the class will try to read the MAGIC environment variable
  845. * and if it is empty, will default to '/usr/share/file/magic'
  846. * If set to an empty string, it will call finfo_open without the path argument
  847. *
  848. * This variable is set to true by default for security reason
  849. *
  850. * @access public
  851. * @var boolean
  852. */
  853. var $mime_fileinfo;
  854. /**
  855. * Set this variable to false in the init() function if you don't want to check the MIME
  856. * with UNIX file() command
  857. *
  858. * This variable is set to true by default for security reason
  859. *
  860. * @access public
  861. * @var boolean
  862. */
  863. var $mime_file;
  864. /**
  865. * Set this variable to false in the init() function if you don't want to check the MIME
  866. * with the magic.mime file
  867. *
  868. * The function mime_content_type() will be deprecated,
  869. * and this variable will be set to false in a future release
  870. *
  871. * This variable is set to true by default for security reason
  872. *
  873. * @access public
  874. * @var boolean
  875. */
  876. var $mime_magic;
  877. /**
  878. * Set this variable to false in the init() function if you don't want to check the MIME
  879. * with getimagesize()
  880. *
  881. * The class tries to get a MIME type from getimagesize()
  882. * If no MIME is returned, it tries to guess the MIME type from the file type
  883. *
  884. * This variable is set to true by default for security reason
  885. *
  886. * @access public
  887. * @var boolean
  888. */
  889. var $mime_getimagesize;
  890. /**
  891. * Set this variable to false if you don't want to turn dangerous scripts into simple text files
  892. *
  893. * @access public
  894. * @var boolean
  895. */
  896. var $no_script;
  897. /**
  898. * Set this variable to true to allow automatic renaming of the file
  899. * if the file already exists
  900. *
  901. * Default value is true
  902. *
  903. * For instance, on uploading foo.ext,<br>
  904. * if foo.ext already exists, upload will be renamed foo_1.ext<br>
  905. * and if foo_1.ext already exists, upload will be renamed foo_2.ext<br>
  906. *
  907. * Note that this option doesn't have any effect if {@link file_overwrite} is true
  908. *
  909. * @access public
  910. * @var bool
  911. */
  912. var $file_auto_rename;
  913. /**
  914. * Set this variable to true to allow automatic creation of the destination
  915. * directory if it is missing (works recursively)
  916. *
  917. * Default value is true
  918. *
  919. * @access public
  920. * @var bool
  921. */
  922. var $dir_auto_create;
  923. /**
  924. * Set this variable to true to allow automatic chmod of the destination
  925. * directory if it is not writeable
  926. *
  927. * Default value is true
  928. *
  929. * @access public
  930. * @var bool
  931. */
  932. var $dir_auto_chmod;
  933. /**
  934. * Set this variable to the default chmod you want the class to use
  935. * when creating directories, or attempting to write in a directory
  936. *
  937. * Default value is 0777 (without quotes)
  938. *
  939. * @access public
  940. * @var bool
  941. */
  942. var $d

Large files files are truncated, but you can click here to view the full file