A PHP multi-image upload Class code example

Source: Internet
Author: User

How to use: Save the above code with the file name: more_upload_file.class.php, and include the file when you use it.

'; } function Move_file (mvfiletmp, Mvfilename) {//move file Mvfilenamearr = Explode ('. ', basename (Mvfilename)); mvfilenamearr[0 ] = this, rand_string (); Mvfilename = Implode ('. ', Mvfilenamearr); if (Is_uploaded_file (mvfiletmp)) {uploadfile = self:: File_path. "Mvfilename"; result = Move_uploaded_file (mvfiletmp, UploadFile); return result; }} function Rand_string () {string = MD5 (Uniqid (rand (). Microtime ())); return string;} function size_bkm (size) {//b/kb/ MB Unit conversion if (size < 1024x768) {size_bkm = (string) size. "B"; } elseif (Size < (1024x768)) {size_bkm = Number_format ((double) (size/1024), 1). "KB"; }else {size_bkm = Number_format ((double) (Size/(1024 * 1024)), 1). "MB"; } return size_bkm; }}?>
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 '
' . Smfilename. ' ' . Smfiletype. ' ' . Smfilesizeformat. ' ' . Smfilemessage. '
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.