class.upload.php is a powerful and mature PHP class to manage uploaded files, and manipulate images in many ways. The script is available under a GPL license.
system information - class version : 0.30 - operating system : WINNT - PHP version : 5.3.5 - GD version : 2.0.34 - supported image types : png jpg gif bmp - open_basedir : no restriction - upload_max_filesize : 99999999999999999M (1.048576E+23 bytes) - language : en_GB source is an uploaded file - upload OK - file name OK determining MIME type - Checking MIME type with Fileinfo PECL extension Fileinfo PECL extension not available - Checking MIME type with UNIX file() command UNIX file() command not availabled - Checking MIME type with mime.magic file (mime_content_type()) mime_content_type() is not available - Checking MIME type with getimagesize() MIME type detected as image/jpeg by PHP getimagesize() function - MIME validated as image/jpeg source variables - You can use all these before calling process() file_src_name : nav-03.jpg file_src_name_body : nav-03 file_src_name_ext : jpg file_src_pathname : C:\wamp\tmp\php77A5.tmp file_src_mime : image/jpeg file_src_size : 5213 (max= 1.048576E+23) file_src_error : 0 - source file is an image image_src_x : 100 image_src_y : 100 image_src_pixels : 10000 image_src_type : jpg image_src_bits : 8 process file to panadol_content/files/uploads/\ - file size OK - file mime OK : image/jpeg - file name body prepend : 2011-11-12_ - file name safe format - destination variables file_dst_path : panadol_content/files/uploads/\ file_dst_name_body : 2011_11_12_nav_03 file_dst_name_ext : jpg - image operation, keep extension - checking for auto_rename - destination file details file_dst_name : 2011_11_12_nav_03.jpg file_dst_pathname : panadol_content/files/uploads/\2011_11_12_nav_03.jpg - 2011_11_12_nav_03.jpg doesn't exist already - image resizing or conversion wanted - source image is JPEG - setting destination file type to jpg - add text - converting... fills in transparency with default color - saving image... JPEG image created image objects destroyed - process OK process file to panadol_content/files/uploads/\ - file size OK - file mime OK : image/jpeg - file name body append : _th - file name body prepend : 2011-11-12_ - file name safe format - destination variables file_dst_path : panadol_content/files/uploads/\ file_dst_name_body : 2011_11_12_nav_03_th file_dst_name_ext : jpg - image operation, keep extension - checking for auto_rename - destination file details file_dst_name : 2011_11_12_nav_03_th.jpg file_dst_pathname : panadol_content/files/uploads/\2011_11_12_nav_03_th.jpg - 2011_11_12_nav_03_th.jpg doesn't exist already - image resizing or conversion wanted - source image is JPEG - setting destination file type to jpg - resizing... check x/y sizes ratio_crop_y : 0 (0;0) resized image object created image_src_x y : 100 x 100 image_dst_x y : 150 x 150 - crop image : 0 0 0 0 - converting... fills in transparency with default color - saving image... JPEG image created image objects destroyed - process OK
Here's my script.
$files = array(); foreach ( $_FILES['files'] as $k => $l ) { foreach ( $l as $i => $v ) { //die( print_r( $_FILES, 1 ) ); if ( ! array_key_exists( $i, $files ) ) $files[$i] = array(); $files[$i][$k] = $v; } } foreach ( $files as $file ) { $upload = new Upload( $file ); $suffix = date( 'Y-m-d' ) . '_'; //$upload->mime_check = true; $upload->file_name_body_pre = $suffix; if ( $upload->uploaded ) { $upload->jpeg_quality = panadol_option( 'media_quality' ); if ( panadol_option( 'media_watermark' ) == 'enabled' ) { /** Create watermark. */ $upload->image_text = panadol_option( 'media_watermark_text' ); $upload->image_text_font = panadol_option( 'media_watermark_text_size' ); $upload->image_text_color = panadol_option( 'media_watermark_text_color' ); $upload->image_text_position = 'BR'; $upload->image_text_padding_x = 5; $upload->image_text_padding_y = 5; } $upload->Process( panadol_option( 'upload_url_path' ) . panadol_media_type( $upload->file_src_mime ) ); /** Create image thumbnail. */ $image_is_allowed = $upload->allowed = array( 'image/*' ); if ( $image_is_allowed ) { $upload->file_name_body_pre = $suffix; $upload->image_resize = true; $upload->image_ratio_crop = true; $upload->image_x = panadol_option( 'thumbnail_size_w' ); $upload->image_y = panadol_option( 'thumbnail_size_h' ); $upload->jpeg_quality = panadol_option( 'thumbnail_quality' ); $upload->file_name_body_add = panadol_option( 'thumbnail_append' ); $upload->Process( panadol_option( 'upload_url_path' ) . panadol_media_type( $upload->file_src_mime ) ); } if ( $upload->processed ) { $database = MEDIA_TBL; mysql_query( "INSERT INTO $database ( media_title, media_filename, media_title_uneditable, media_date, media_extension, media_type ) VALUES ( '$upload->file_dst_name_body', '$upload->file_dst_name', '$upload->file_dst_name_body', NOW(), '$upload->file_dst_name_ext', '$upload->file_src_mime' )" ) or die( panadol_database() ); header( 'Location: ' . panadol_sanitize( panadol_cleanurl( '?load=admin§ion=upload-a-media&save=success' ), 'htmlentity_decode' ) ); exit; } else { header( 'Location: ' . panadol_sanitize( panadol_cleanurl( '?load=admin§ion=upload-a-media&save=error' ), 'htmlentity_decode' ) ); exit; } $upload-> Clean(); } else { header( 'Location: ' . panadol_sanitize( panadol_cleanurl( '?load=admin§ion=upload-a-media&save=error' ), 'htmlentity_decode' ) ); exit; } }Thank you for creating this great script.
- class version : 0.30
- operating system : WINNT
- PHP version : 5.3.5
- GD version : 2.0.34
- supported image types : png jpg gif bmp
- open_basedir : no restriction
- upload_max_filesize : 99999999999999999M (1.048576E+23 bytes)
- language : en_GB
source is an uploaded file
- upload OK
- file name OK
determining MIME type
- Checking MIME type with Fileinfo PECL extension
Fileinfo PECL extension not available
- Checking MIME type with UNIX file() command
UNIX file() command not availabled
- Checking MIME type with mime.magic file (mime_content_type())
mime_content_type() is not available
- Checking MIME type with getimagesize()
MIME type detected as image/jpeg by PHP getimagesize() function
- MIME validated as image/jpeg
source variables
- You can use all these before calling process()
file_src_name : nav-03.jpg
file_src_name_body : nav-03
file_src_name_ext : jpg
file_src_pathname : C:\wamp\tmp\php77A5.tmp
file_src_mime : image/jpeg
file_src_size : 5213 (max= 1.048576E+23)
file_src_error : 0
- source file is an image
image_src_x : 100
image_src_y : 100
image_src_pixels : 10000
image_src_type : jpg
image_src_bits : 8
process file to panadol_content/files/uploads/\
- file size OK
- file mime OK : image/jpeg
- file name body prepend : 2011-11-12_
- file name safe format
- destination variables
file_dst_path : panadol_content/files/uploads/\
file_dst_name_body : 2011_11_12_nav_03
file_dst_name_ext : jpg
- image operation, keep extension
- checking for auto_rename
- destination file details
file_dst_name : 2011_11_12_nav_03.jpg
file_dst_pathname : panadol_content/files/uploads/\2011_11_12_nav_03.jpg
- 2011_11_12_nav_03.jpg doesn't exist already
- image resizing or conversion wanted
- source image is JPEG
- setting destination file type to jpg
- add text
- converting...
fills in transparency with default color
- saving image...
JPEG image created
image objects destroyed
- process OK
process file to panadol_content/files/uploads/\
- file size OK
- file mime OK : image/jpeg
- file name body append : _th
- file name body prepend : 2011-11-12_
- file name safe format
- destination variables
file_dst_path : panadol_content/files/uploads/\
file_dst_name_body : 2011_11_12_nav_03_th
file_dst_name_ext : jpg
- image operation, keep extension
- checking for auto_rename
- destination file details
file_dst_name : 2011_11_12_nav_03_th.jpg
file_dst_pathname : panadol_content/files/uploads/\2011_11_12_nav_03_th.jpg
- 2011_11_12_nav_03_th.jpg doesn't exist already
- image resizing or conversion wanted
- source image is JPEG
- setting destination file type to jpg
- resizing...
check x/y sizes
ratio_crop_y : 0 (0;0)
resized image object created
image_src_x y : 100 x 100
image_dst_x y : 150 x 150
- crop image : 0 0 0 0
- converting...
fills in transparency with default color
- saving image...
JPEG image created
image objects destroyed
- process OK
Thank you for the good work.
Great script thanks for the hard work.
$files = array(); foreach ( $_FILES['images'] as $k => $l ) { foreach ( $l as $i => $v ) { //die( print_r( $_FILES, 1 ) ); if ( ! array_key_exists( $i, $files ) ) $files[$i] = array(); $files[$i][$k] = $v; } } foreach ( $files as $get_files ) { $upload = new Upload( $get_files ); $suffix = date( 'Y-m-d' ) . '_'; $upload->mime_check = true; $upload->file_name_body_pre = $suffix; $upload->jpeg_quality = panadol_option( 'media_quality' ); if ( $upload->uploaded ) { if ( panadol_option( 'media_watermark' ) == 'enabled' ) { /** Create watermark. */ $upload->image_text = panadol_option( 'media_watermark_text' ); $upload->image_text_font = panadol_option( 'media_watermark_text_size' ); $upload->image_text_color = panadol_option( 'media_watermark_text_color' ); $upload->image_text_position = 'BR'; $upload->image_text_padding_x = 5; $upload->image_text_padding_y = 5; } $upload->Process( panadol_option( 'upload_path' ) ); /** Create image thumbnail. */ $image_is_allowed = $upload->allowed = array( 'image/*' ); if ( $image_is_allowed ) { $upload->file_name_body_pre = $suffix; $upload->image_resize = true; $upload->image_ratio_crop = true; $upload->image_x = panadol_option( 'thumbnail_size_w' ); $upload->image_y = panadol_option( 'thumbnail_size_h' ); $upload->jpeg_quality = panadol_option( 'thumbnail_quality' ); $upload->file_name_body_add = panadol_option( 'thumbnail_append' ); $upload->Process( panadol_option( 'upload_path' ) ); } $database = MEDIA_TBL; mysql_query( "INSERT INTO $database ( media_title, media_filename, media_title_uneditable, media_date, media_extension, media_type ) VALUES ( '$upload->file_dst_name_body', '$upload->file_dst_name', '$upload->file_dst_name_body', NOW(), '$upload->file_dst_name_ext', '$upload->file_src_mime' )" ) or die( panadol_database() ); } elseif ( $upload->processed ) { header( 'Location: ' . panadol_sanitize( panadol_cleanurl( '?load=admin§ion=upload-a-media&save=success' ), 'htmlentity_decode' ) ); exit; } else { header( 'Location: ' . panadol_sanitize( panadol_cleanurl( '?load=admin§ion=upload-a-media&save=error' ), 'htmlentity_decode' ) ); exit; } //die( $upload->log ); $upload-> Clean(); }