| Share a PHP class for multi-image upload. this class of File annotation is practical and extensible. it supports multiimage Upload in gif, jpg, jpeg, pjpeg, and png formats, A rare php multi-image upload class.
A Practical PHP multi-image file Upload class that supports the multiimage Upload function in gif, jpg, jpeg, pjpeg, and png formats, you can also restrict the image type, size of the uploaded image, set the upload directory, and submit and determine some other functions. In addition, this class is not limited to image upload. you can also upload file types such as TXT and RAR, but you just need to modify the code.
For example, php full function code for multiimage Upload.
Handledate = date ('M-d-y'); if (! Empty (file_name) {this-> file_name = file_name; this-> file_error = file_error; this-> file_size = file_size; this-> file_tmp_name = file_tmp_name; this-> file_type = file_type; this-> file_type_array = array ('/', 'image/GIF', 'image/jpg ', 'image/jpeg ', 'image/pjpeg ', 'image/png'); this-> file_type_real_array = array (0.1, 'jpg '=> 74707370, 'GIF' => 7173, 'bmp '=> 6677, 'PNG' => 807871); this-> show_execute_message (this-> file_error, this-> file_name, this-> file_type, this-> file_size) ;}} function _ destruct () {this-> file_name = NULL; this-> file_error = NULL; this-> file_size = NULL; this-> file_tmp_name = NULL; this-> file_type = NULL; self: totalsize = 0;} function show_execute_message (smfileerror, smfilename, smfiletype, smfilesize) {if (smfileerror> 0) {switch (smfileerror) {case 1: smfilemessage ='The file size exceeds the server's agreed size!'; Break; case 2: smfilemessage ='The file size exceeds the specified size!'; Break; case 3: smfilemessage ='Only part of the file is uploaded!'; Break; case 4: echo "this-> file_name".' file Upload failed! '; Break;} self: _ destruct ();} else {smfiletypeflag = array_search (smfiletype, this-> file_type_array); // perform real format verification if (smfiletypeflag! = False) {file = fopen (this-> file_tmp_name, "rb"); bin = fread (file, 10); fclose (file ); strInfo = @ unpack ("c10chars", bin); typeCode = intval (strInfo ['chars1']. strInfo ['chars2 ']); smfiletypeflag = array_search (typeCode, this-> file_type_real_array); if (smfiletypeflag = false) {// determine whether a png image is typeCode = intval (strInfo ['chars2']. strInfo ['chars3']. strInfo ['chars4 ']); smfiletypeflag = array_search (typeCode, this-> file_type_real_array); if (smfiletypeflag = false) {// Determine whether the image is a jpg image $ typeCode = intval (strInfo ['chars7 ']. strInfo ['charss']. strInfo ['chars9']. strInfo ['chars10']); smfiletypeflag = array_search (typeCode, this-> file_type_real_array) ;}}// edit: bbs.it-home.org if ($ smfiletypeflag = false) {$ smfilemessage ='Incorrect file type. check the file!'; Self: _ destruct ();} else {$ resflag = $ this-> move_file ($ this-> file_tmp_name, this-> file_name ); if (resflag = 1) {$ smfilemessage = 'file uploaded successfully! '; Self: totalsize + = intval ($ smfilesize); self: _ destruct ();} else {$ smfilemessage ='File upload failed!'; Self: _ destruct () ;}}$ smfilesizeformat = $ this-> size_BKM (smfilesize); echo' |