x {@link image_y}, * but only if original image is smaller * * Default value is false * * @access public * @var bool */ var $image_ratio_no_zoom_out; /** * 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; /** * 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; /** * 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 * * Value is in bytes. The JPG quality will be set between 1 and 100% * The calculations are approximations. * * Default value is null (no calculations) * * @access public * @var integer */ var $jpeg_size; /** * Preserve transparency when resizing or converting an image (deprecated) * * Default value is automatically set to true for transparent GIFs * This setting is now deprecated * * @access public * @var integer */ var $preserve_transparency; /** * 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; /** * 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_percent} * * Default value is null * * @access public * @var string; */ var $image_overlay_color; /** * Sets the percentage for the colored overlay * * Value is a percentage, as an integer between 0 and 100 * * Unless used with {@link image_overlay_color}, this setting has no effect * * Default value is 50 * * @access public * @var integer */ var $image_overlay_percent; /** * 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; /** * Adds a text label on the image * * Value is a string, any text. Text will not word-wrap, although you can use breaklines in your text "\n" * * If set, this setting allow the use of all other settings starting with image_text_ * * Replacement tokens can be used in the string: *
* gd_version src_name src_name_body src_name_ext
* src_pathname src_mime src_x src_y
* src_type src_bits src_pixels
* src_size src_size_kb src_size_mb src_size_human
* dst_path dst_name_body dst_pathname
* dst_name dst_name_ext dst_x dst_y
* date time host server ip
*
* The tokens must be enclosed in square brackets: [dst_x] will be replaced by the width of the picture
*
* Default value is null
*
* @access public
* @var string;
*/
var $image_text;
/**
* Sets the text direction for the text label
*
* Value is either 'h' or 'v', as in horizontal and vertical
*
* Default value is h (horizontal)
*
* @access public
* @var string;
*/
var $image_text_direction;
/**
* Sets the text color for the text label
*
* Value is an hexadecimal color, such as #FFFFFF
*
* Default value is #FFFFFF (white)
*
* @access public
* @var string;
*/
var $image_text_color;
/**
* Sets the text visibility in the text label
*
* Value is a percentage, as an integer between 0 and 100
*
* Default value is 100
*
* @access public
* @var integer
*/
var $image_text_percent;
/**
* Sets the text background color for the text label
*
* Value is an hexadecimal color, such as #FFFFFF
*
* Default value is null (no background)
*
* @access public
* @var string;
*/
var $image_text_background;
/**
* Sets the text background visibility in the text label
*
* Value is a percentage, as an integer between 0 and 100
*
* Default value is 100
*
* @access public
* @var integer
*/
var $image_text_background_percent;
/**
* Sets the text font in the text label
*
* Value is a an integer between 1 and 5 for GD built-in fonts. 1 is the smallest font, 5 the biggest
* Value can also be a string, which represents the path to a GDF font. The font will be loaded into GD, and used as a built-in font.
*
* Default value is 5
*
* @access public
* @var mixed;
*/
var $image_text_font;
/**
* Sets the text label position within the image
*
* Value is one or two out of 'TBLR' (top, bottom, left, right)
*
* The positions are as following:
*
* TL T TR
* L R
* BL B BR
*
*
* Default value is null (centered, horizontal and vertical)
*
* Note that is {@link image_text_x} and {@link image_text_y} are used, this setting has no effect
*
* @access public
* @var string;
*/
var $image_text_position;
/**
* Sets the text label absolute X position within the image
*
* Value is in pixels, representing the distance between the left of the image and the label
* If a negative value is used, it will represent the distance between the right of the image and the label
*
* Default value is null (so {@link image_text_position} is used)
*
* @access public
* @var integer
*/
var $image_text_x;
/**
* Sets the text label absolute Y position within the image
*
* Value is in pixels, representing the distance between the top of the image and the label
* If a negative value is used, it will represent the distance between the bottom of the image and the label
*
* Default value is null (so {@link image_text_position} is used)
*
* @access public
* @var integer
*/
var $image_text_y;
/**
* Sets the text label padding
*
* Value is in pixels, representing the distance between the text and the label background border
*
* Default value is 0
*
* This setting can be overriden by {@link image_text_padding_x} and {@link image_text_padding_y}
*
* @access public
* @var integer
*/
var $image_text_padding;
/**
* Sets the text label horizontal padding
*
* Value is in pixels, representing the distance between the text and the left and right label background borders
*
* Default value is null
*
* If set, this setting overrides the horizontal part of {@link image_text_padding}
*
* @access public
* @var integer
*/
var $image_text_padding_x;
/**
* Sets the text label vertical padding
*
* Value is in pixels, representing the distance between the text and the top and bottom label background borders
*
* Default value is null
*
* If set, his setting overrides the vertical part of {@link image_text_padding}
*
* @access public
* @var integer
*/
var $image_text_padding_y;
/**
* Sets the text alignment
*
* Value is a string, which can be either 'L', 'C' or 'R'
*
* Default value is 'C'
*
* This setting is relevant only if the text has several lines.
*
* @access public
* @var string;
*/
var $image_text_alignment;
/**
* Sets the text line spacing
*
* Value is an integer, in pixels
*
* Default value is 0
*
* This setting is relevant only if the text has several lines.
*
* @access public
* @var integer
*/
var $image_text_line_spacing;
/**
* Sets the height of the reflection
*
* Value is an integer in pixels, or a string which format can be in pixels or percentage.
* For instance, values can be : 40, '40', '40px' or '40%'
*
* Default value is null, no reflection
*
* @access public
* @var mixed;
*/
var $image_reflection_height;
/**
* Sets the space between the source image and its relection
*
* Value is an integer in pixels, which can be negative
*
* Default value is 2
*
* This setting is relevant only if {@link image_reflection_height} is set
*
* @access public
* @var integer
*/
var $image_reflection_space;
/**
* Sets the color of the reflection background (deprecated)
*
* Value is an hexadecimal color, such as #FFFFFF
*
* Default value is #FFFFFF
*
* This setting is relevant only if {@link image_reflection_height} is set
*
* This setting is now deprecated in favor of {@link image_default_color}
*
* @access public
* @var string;
*/
var $image_reflection_color;
/**
* Sets the initial opacity of the reflection
*
* Value is an integer between 0 (no opacity) and 100 (full opacity).
* The reflection will start from {@link image_reflection_opacity} and end up at 0
*
* Default value is 60
*
* This setting is relevant only if {@link image_reflection_height} is set
*
* @access public
* @var integer
*/
var $image_reflection_opacity;
/**
* Flips the image vertically or horizontally
*
* Value is either 'h' or 'v', as in horizontal and vertical
*
* Default value is null (no flip)
*
* @access public
* @var string;
*/
var $image_flip;
/**
* Rotates the image by increments of 45 degrees
*
* Value is either 90, 180 or 270
*
* Default value is null (no rotation)
*
* @access public
* @var string;
*/
var $image_rotate;
/**
* Crops an image
*
* Values are four dimensions, or two, or one (CSS style)
* They represent the amount cropped top, right, bottom and left.
* These values can either be in an array, or a space separated string.
* Each value can be in pixels (with or without 'px'), or percentage (of the source image)
*
* For instance, are valid:
*
* $foo->image_crop = 20 OR array(20);
* $foo->image_crop = '20px' OR array('20px');
* $foo->image_crop = '20 40' OR array('20', 40);
* $foo->image_crop = '-20 25%' OR array(-20, '25%');
* $foo->image_crop = '20px 25%' OR array('20px', '25%');
* $foo->image_crop = '20% 25%' OR array('20%', '25%');
* $foo->image_crop = '20% 25% 10% 30%' OR array('20%', '25%', '10%', '30%');
* $foo->image_crop = '20px 25px 2px 2px' OR array('20px', '25%px', '2px', '2px');
* $foo->image_crop = '20 25% 40px 10%' OR array(20, '25%', '40px', '10%');
*
*
* If a value is negative, the image will be expanded, and the extra parts will be filled with black
*
* Default value is null (no cropping)
*
* @access public
* @var string OR array;
*/
var $image_crop;
/**
* Adds a bevel border on the image
*
* Value is a positive integer, representing the thickness of the bevel
*
* If the bevel colors are the same as the background, it makes a fade out effect
*
* Default value is null (no bevel)
*
* @access public
* @var integer
*/
var $image_bevel;
/**
* Top and left bevel color
*
* Value is a color, in hexadecimal format
* This setting is used only if {@link image_bevel} is set
*
* Default value is #FFFFFF
*
* @access public
* @var string;
*/
var $image_bevel_color1;
/**
* Right and bottom bevel color
*
* Value is a color, in hexadecimal format
* This setting is used only if {@link image_bevel} is set
*
* Default value is #000000
*
* @access public
* @var string;
*/
var $image_bevel_color2;
/**
* Adds a single-color border on the outer of the image
*
* Values are four dimensions, or two, or one (CSS style)
* They represent the border thickness top, right, bottom and left.
* These values can either be in an array, or a space separated string.
* Each value can be in pixels (with or without 'px'), or percentage (of the source image)
*
* See {@link image_crop} for valid formats
*
* If a value is negative, the image will be cropped.
* Note that the dimensions of the picture will be increased by the borders' thickness
*
* Default value is null (no border)
*
* @access public
* @var integer
*/
var $image_border;
/**
* Border color
*
* Value is a color, in hexadecimal format.
* This setting is used only if {@link image_border} is set
*
* Default value is #FFFFFF
*
* @access public
* @var string;
*/
var $image_border_color;
/**
* Adds a multi-color frame on the outer of the image
*
* Value is an integer. Two values are possible for now:
* 1 for flat border, meaning that the frame is mirrored horizontally and vertically
* 2 for crossed border, meaning that the frame will be inversed, as in a bevel effect
*
* The frame will be composed of colored lines set in {@link image_frame_colors}
*
* Note that the dimensions of the picture will be increased by the borders' thickness
*
* Default value is null (no frame)
*
* @access public
* @var integer
*/
var $image_frame;
/**
* Sets the colors used to draw a frame
*
* Values is a list of n colors in hexadecimal format.
* These values can either be in an array, or a space separated string.
*
* The colors are listed in the following order: from the outset of the image to its center
*
* For instance, are valid:
*
* $foo->image_frame_colors = '#FFFFFF #999999 #666666 #000000';
* $foo->image_frame_colors = array('#FFFFFF', '#999999', '#666666', '#000000');
*
*
* This setting is used only if {@link image_frame} is set
*
* Default value is '#FFFFFF #999999 #666666 #000000'
*
* @access public
* @var string OR array;
*/
var $image_frame_colors;
/**
* Adds a watermark on the image
*
* Value is a local image filename, relative or absolute. GIF, JPG, BMP and PNG are supported, as well as PNG alpha.
*
* If set, this setting allow the use of all other settings starting with image_watermark_
*
* Default value is null
*
* @access public
* @var string;
*/
var $image_watermark;
/**
* Sets the watermarkposition within the image
*
* Value is one or two out of 'TBLR' (top, bottom, left, right)
*
* The positions are as following: TL T TR
* L R
* BL B BR
*
* Default value is null (centered, horizontal and vertical)
*
* Note that is {@link image_watermark_x} and {@link image_watermark_y} are used, this setting has no effect
*
* @access public
* @var string;
*/
var $image_watermark_position;
/**
* Sets the watermark absolute X position within the image
*
* Value is in pixels, representing the distance between the top of the image and the watermark
* If a negative value is used, it will represent the distance between the bottom of the image and the watermark
*
* Default value is null (so {@link image_watermark_position} is used)
*
* @access public
* @var integer
*/
var $image_watermark_x;
/**
* Sets the twatermark absolute Y position within the image
*
* Value is in pixels, representing the distance between the left of the image and the watermark
* If a negative value is used, it will represent the distance between the right of the image and the watermark
*
* Default value is null (so {@link image_watermark_position} is used)
*
* @access public
* @var integer
*/
var $image_watermark_y;
/**
* Allowed MIME types
*
* Default is a selection of safe mime-types, but you might want to change it
*
* Simple wildcards are allowed, such as image/* or application/*
*
* @access public
* @var array
*/
var $allowed;
/**
* Forbidden MIME types
*
* Default is a selection of safe mime-types, but you might want to change it
* To only check for forbidden MIME types, and allow everything else, set {@link allowed} to array('* / *') without the spaces
*
* Simple wildcards are allowed, such as image/* or application/*
*
* @access public
* @var array
*/
var $forbidden;
/**
* Array of translated error messages
*
* By default, the language is english (en_GB)
* Translations can be in separate files, in a lang/ subdirectory
*
* @access public
* @var array
*/
var $translation;
/**
* Language selected for the translations
*
* By default, the language is english ("en_GB")
*
* @access public
* @var array
*/
var $language;
/**
* Init or re-init all the processing variables to their default values
*
* This function is called in the constructor, and after each call of {@link process}
*
* @access private
*/
function init() {
// overiddable variables
$this->file_new_name_body = ''; // replace the name body
$this->file_name_body_add = ''; // append to the name body
$this->file_new_name_ext = ''; // replace the file extension
$this->file_safe_name = true; // format safely the filename
$this->file_overwrite = false; // allows overwritting if the file already exists
$this->file_auto_rename = true; // auto-rename if the file already exists
$this->dir_auto_create = true; // auto-creates directory if missing
$this->dir_auto_chmod = true; // auto-chmod directory if not writeable
$this->dir_chmod = 0777; // default chmod to use
$this->mime_check = true; // don't check the mime type against the allowed list
$this->mime_magic_check = false; // don't double check the MIME type with mime_magic
$this->no_script = true; // turns scripts into test files
$val = trim(ini_get('upload_max_filesize'));
$last = strtolower($val{strlen($val)-1});
switch($last) {
case 'g':
$val *= 1024;
case 'm':
$val *= 1024;
case 'k':
$val *= 1024;
}
$this->file_max_size = $val;
$this->image_resize = false; // resize the image
$this->image_convert = ''; // convert. values :''; 'png'; 'jpeg'; 'gif'; 'bmp'
$this->image_x = 150;
$this->image_y = 150;
$this->image_ratio = false; // keeps aspect ratio with x and y dimensions
$this->image_ratio_crop = false; // keeps aspect ratio with x and y dimensions, filling the space
$this->image_ratio_fill = false; // keeps aspect ratio with x and y dimensions, fitting the image in the space, and coloring the rest
$this->image_ratio_pixels = false; // keeps aspect ratio, calculating x and y so that the image is approx the set number of pixels
$this->image_ratio_no_zoom_in = false;
$this->image_ratio_no_zoom_out = false;
$this->image_ratio_x = false; // calculate the $image_x if true
$this->image_ratio_y = false; // calculate the $image_y if true
$this->jpeg_quality = 85;
$this->jpeg_size = null;
$this->preserve_transparency = false;
$this->image_is_transparent = false;
$this->image_transparent_color = null;
$this->image_background_color = null;
$this->image_default_color = '#ffffff';
$this->image_is_palette = false;
$this->image_max_width = null;
$this->image_max_height = null;
$this->image_max_pixels = null;
$this->image_max_ratio = null;
$this->image_min_width = null;
$this->image_min_height = null;
$this->image_min_pixels = null;
$this->image_min_ratio = null;
$this->image_brightness = null;
$this->image_contrast = null;
$this->image_threshold = null;
$this->image_tint_color = null;
$this->image_overlay_color = null;
$this->image_overlay_percent = null;
$this->image_negative = false;
$this->image_greyscale = false;
$this->image_text = null;
$this->image_text_direction = null;
$this->image_text_color = '#FFFFFF';
$this->image_text_percent = 100;
$this->image_text_background = null;
$this->image_text_background_percent = 100;
$this->image_text_font = 5;
$this->image_text_x = null;
$this->image_text_y = null;
$this->image_text_position = null;
$this->image_text_padding = 0;
$this->image_text_padding_x = null;
$this->image_text_padding_y = null;
$this->image_text_alignment = 'C';
$this->image_text_line_spacing = 0;
$this->image_reflection_height = null;
$this->image_reflection_space = 2;
$this->image_reflection_color = '#ffffff';
$this->image_reflection_opacity = 60;
$this->image_watermark = null;
$this->image_watermark_x = null;
$this->image_watermark_y = null;
$this->image_watermark_position = null;
$this->image_flip = null;
$this->image_rotate = null;
$this->image_crop = null;
$this->image_bevel = null;
$this->image_bevel_color1 = '#FFFFFF';
$this->image_bevel_color2 = '#000000';
$this->image_border = null;
$this->image_border_color = '#FFFFFF';
$this->image_frame = null;
$this->image_frame_colors = '#FFFFFF #999999 #666666 #000000';
$this->forbidden = array();
$this->allowed = array("application/rar",
"application/x-rar-compressed",
"application/arj",
"application/excel",
"application/gnutar",
"application/octet-stream",
"application/pdf",
"application/powerpoint",
"application/postscript",
"application/plain",
"application/rtf",
"application/vocaltec-media-file",
"application/wordperfect",
"application/x-bzip",
"application/x-bzip2",
"application/x-compressed",
"application/x-excel",
"application/x-gzip",
"application/x-latex",
"application/x-midi",
"application/x-msexcel",
"application/x-rtf",
"application/x-sit",
"application/x-stuffit",
"application/x-shockwave-flash",
"application/x-troff-msvideo",
"application/x-zip-compressed",
"application/xml",
"application/zip",
"application/msword",
"application/mspowerpoint",
"application/vnd.ms-excel",
"application/vnd.ms-powerpoint",
"application/vnd.ms-word",
"application/vnd.ms-word.document.macroEnabled.12",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"application/vnd.ms-word.template.macroEnabled.12",
"application/vnd.openxmlformats-officedocument.wordprocessingml.template",
"application/vnd.ms-powerpoint.template.macroEnabled.12",
"application/vnd.openxmlformats-officedocument.presentationml.template",
"application/vnd.ms-powerpoint.addin.macroEnabled.12",
"application/vnd.ms-powerpoint.slideshow.macroEnabled.12",
"application/vnd.openxmlformats-officedocument.presentationml.slideshow",
"application/vnd.ms-powerpoint.presentation.macroEnabled.12",
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
"application/vnd.ms-excel.addin.macroEnabled.12",
"application/vnd.ms-excel.sheet.binary.macroEnabled.12",
"application/vnd.ms-excel.sheet.macroEnabled.12",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"application/vnd.ms-excel.template.macroEnabled.12",
"application/vnd.openxmlformats-officedocument.spreadsheetml.template",
"audio/*",
"image/*",
"video/*",
"multipart/x-zip",
"multipart/x-gzip",
"text/richtext",
"text/plain",
"text/xml");
}
/**
* Constructor. Checks if the file has been uploaded
*
* The constructor takes $_FILES['form_field'] array as argument
* where form_field is the form field name
*
* The constructor will check if the file has been uploaded in its temporary location, and
* accordingly will set {@link uploaded} (and {@link error} is an error occurred)
*
* If the file has been uploaded, the constructor will populate all the variables holding the upload
* information (none of the processing class variables are used here).
* You can have access to information about the file (name, size, MIME type...).
*
*
* Alternatively, you can set the first argument to be a local filename (string)
* This allows processing of a local file, as if the file was uploaded
*
* The optional second argument allows you to set the language for the error messages
*
* @access private
* @param array $file $_FILES['form_field']
* or string $file Local filename
* @param string $lang Optional language code
*/
function upload($file, $lang = 'en_GB') {
$this->file_src_name = '';
$this->file_src_name_body = '';
$this->file_src_name_ext = '';
$this->file_src_mime = '';
$this->file_src_size = '';
$this->file_src_error = '';
$this->file_src_pathname = '';
$this->file_src_temp = '';
$this->file_dst_path = '';
$this->file_dst_name = '';
$this->file_dst_name_body = '';
$this->file_dst_name_ext = '';
$this->file_dst_pathname = '';
$this->image_src_x = null;
$this->image_src_y = null;
$this->image_src_bits = null;
$this->image_src_type = null;
$this->image_src_pixels = null;
$this->image_dst_x = 0;
$this->image_dst_y = 0;
$this->uploaded = true;
$this->no_upload_check = false;
$this->processed = true;
$this->error = '';
$this->log = '';
$this->allowed = array();
$this->forbidden = array();
$this->file_is_image = false;
$this->init();
$info = null;
// sets default language
$this->translation = array();
$this->translation['file_error'] = 'File error. Please try again.';
$this->translation['local_file_missing'] = 'Local file doesn\'t exist.';
$this->translation['local_file_not_readable'] = 'Local file is not readable.';
$this->translation['uploaded_too_big_ini'] = 'File upload error (the uploaded file exceeds the upload_max_filesize directive in php.ini).';
$this->translation['uploaded_too_big_html'] = 'File upload error (the uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form).';
$this->translation['uploaded_partial'] = 'File upload error (the uploaded file was only partially uploaded).';
$this->translation['uploaded_missing'] = 'File upload error (no file was uploaded).';
$this->translation['uploaded_unknown'] = 'File upload error (unkn