Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.

upload_image

Upload given image securely and with as little error messages as possible. The function can also create two thumbnails automatically where you set the specifications for both and gives you total control over the upload process.

upload_image

Quote

upload_image ( string $source_image, string $target_name, string $target_folder, numeric $target_width, numberic $target_height, numeric $max_size, bool $delete_original, bool $thumb1, bool $thumb2, numeric $thumb1_ratio, string $thumb1_folder, string $thumb1_suffix, numeric $thumb1_width, numeric $thumb1_height, numeric $thumb2_ratio, string $thumb2_folder, string $thumb2_suffix, numeric $thumb2_width, numeric $thumb2_height, string $query )


Parameters
source_image
Key for the uploaded file in the $_FILES[] array.

target_name
Name of the uploaded image, leave this blank to use the original image name.

target_folder
The folder you are uploading the image to.

target_width
Maximum allowed width of image in pixels, default is 1800 pixels.

target_height
Maximum allowed height of image in pixels, default is 1600 pixels.

max_size
Max size of image in bytes, default is 150000 bytes.

delete_original
Set this to true if you wish the original image to be delete after upload, default for this is true.

thumb1
Set this to true if you wish to generate a thumbnail number 1, default is false.

thumb2
Set this to true if you wish to generate a thumbnail number 2, default is false.

thumb1_ratio
Image ratio for the first thumbnail. 0 means original image ratio, 1 means square image ratio. Default is 0.

thumb1_folder
Folder for the first thumbnail.

thumb1_suffix
Text which will be appended at the end of the image name of the first thumbnail, default is _t1.

thumb1_width
Width of first thumbnail in pixels, default is 100 pixels.

thumb1_height
Height of first thumbnail in pixels, default is 100 pixels.

thumb2_ratio
Image ratio for the second thumbnail. 0 means original image ratio, 1 means square image ratio. Default is 0.

thumb2_folder
Folder for the second thumbnail.

thumb2_suffix
Text which will be appended at the end of the image name of the second thumbnail, default is _t2.

thumb2_width
Width of second thumbnail in pixels, default is 400 pixels.

thumb2_height
Height of first thumbnail in pixels, default is 300 pixels.

query
User defined query when uploading image.

Return Values
Will return an array containing technical information about the upload such as error message and name of the uploaded image.

Example
Code
<?php
require_once INCLUDES."infusions_include.php";
 
// Name of $_FILE key which holds the uploaded image
$image = "myimage";
 
// Left blank to use the image name as it is
$name = "";
 
// Upload folder
$folder = IMAGES;
 
// Maximum image width in pixels
$width = "1800";
 
// Maximum image height in pixels
$height = "1600";
 
// Maximum file size in bytes
$size = "150000";
 
$upload = upload_image($image, $image, $folder, $width, $height, $size);
 
if ($upload['error'] == 1) {
 // Maximum file size exceeded
} elseif ($upload['error'] == 2) {
 // Unsupported image type
} elseif ($upload['error'] == 3) {
 // Invalid image resolution
} elseif ($upload['error'] == 4) {
 // Image not uploaded
} else {
 // Successful upload!
}
?>


Changelog
7.01.01 - Fixed critical error when creating thumbnails.
7.01.00 - Function added to PHPFusion