| Share a PHP implementation of multi-image upload class, the type of file comments detailed features practical and has a certain degree of extensibility, which support GIF, JPG, JPEG, pjpeg, PNG format, multi-image upload function, rare PHP multi-image upload class. A practical PHP multi-image File upload class, which supports GIF, JPG, JPEG, pjpeg, PNG format, multi-image upload function, the class can also limit the type of pictures, upload the size of the image, set the upload directory, some submit judgment and other functions. In addition, the class is not limited to the image upload, you can upload txt/rar and other file types, just need to modify the code. Example, PHP multi-image upload class full function code.
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, File_error, this and file_name, this and File_type, this and 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 = ' file exceeds the contract size of the server! '; Break Case 2:smfilemessage = 'file exceeds the specified file size! '; Break Case 3:smfilemessage = 'only part of the file was uploaded! '; Break Case 4:echo "This->file_name". ' File upload failed! '; Break } Self:: __destruct (); }else{Smfiletypeflag = Array_search (Smfiletype, this, file_type_array); True format validation 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 if png picture TypeCode = intval (strinfo[' chars2 ']. strinfo[' chars3 '. strinfo[' Cha RS4 ']); Smfiletypeflag = Array_search (TypeCode, this, file_type_real_array); if (Smfiletypeflag = = False) {//Determine if it is a jpg picture $typeCode = intval (strinfo[' chars7 '). strinfo[' Chars8 ']. strinfo[' Chars9 ']. strinfo[' Chars10 '); Smfiletypeflag = Array_search (TypeCode, this, file_type_real_array); }}}//edit:bbs.it-home.org if ($smfiletypeflag = = False) {$smfilemessage = ' The file type is wrong, please verify! '; Self:: __destruct (); }else{$resflag = Move_file, $this, $this, File_tmp_name, this, file_name); if (Resflag = = 1) {$smfilemessage = ' file upload succeeded! '; Self:: TotalSize + = Intval ($smfilesize); Self:: __destruct (); }else{$smfilemessage = 'File upload failed! '; Self:: __destruct (); }}} $smfilesizeformat = $this-size_bkm (smfilesize); Echo ' |