Uploaded file PHP class

xiaoxiao2021-03-06  23

Class GggfileUPload {var $ missbug = false; // Setting the debug status, debugging in the class will be wrong, do not debug false true var $ mstrer = "in the class, if ISDEBUG is true, then Automatically abort the program execution after the error, output error message VAR $ miserr = false; // Upload whether an error status flag

VAR $ MISFILHT = true; // Ture will ensure that the file names after the upload can only be made of letters, numbers, upper and downlines, and points; // Ture will use lowercase, due to Win and UNIX The system is sensitive to the file name size, and there will be a lot of troubles in the download file. Var $ mmaxfilenamelen = 30; // The maximum length allowed by file names

VAR $ extfilter = array ('php' => 'php_'); // Set the extension of the extension here, such as the user uploaded .php file is changed to .PHP_ program uses a replacement method such as .php3 Changed to .php_3

Var $ minputname; // The corresponding AAA, * saved a character

VAR $ mfiletype; // Upload type VAR $ mfilesize; // Upload size VAR $ mfilename; // Upload name var $ mfileTmpname; // Uploaded temporary name

VAR $ mfileuppath; // File To Upload Server Address Var $ mfileUpType; // File Upload Allow Type Var $ mfileupSize; // File Upload The Maximum Byte Var $ mfileupname; // Upload the name, That is to change, the name var $ mrorfile = "failt"; // file name is wrong to change the file name starting in MERRORFILE

/ ** ---------------------------------------------- - Function Name: GggfileUPload Features Description: GggfileUPload Initialization Function Description: Class constructor used for initialization class member variable call function: gggfileUpload () Parameters: $ inputname Corresponding AAA, saved Is a character strike $ FILEUPPATH file To Upload Server Address $ FILEUPTYPE File Upload Allow Type $ FileUpsize file Upload Allow Maximum Bytes Default 15000 bytes Back: No Design: GGG Date: 2004-9-1 1 : 17 Modifier: GGG Date: 2004-9-1 1:17 version: 1.0 ** --------------------------- -------------------- * / Function GGGFileUpload ($ INPUTNAME, $ FILEUPPATH, $ fileupType = ", $ fileupsize = 150000) {$ this-> set_file ($ inputName); $ this-> Set_FileUpPath ($ fileUpPath); $ this-> Set_FileUpSize ($ fileUpSize); $ this-> Set_FileUpType ($ fileUpType);} // END GggFileUpload function Show_Debug () {// if ($ this- > MISDEBUG &&! EMPTY ($ this-> get_strer ())))) f ($ this-> MISDEBUG &&! EMPTY ($ this-> mstrerr)) {printf ("
Debug: % S
/ n ", $ this-> get_strerr ());}} // ******************** SET area / / Setup error variable Function set_strerr ($ VarName) {$ this-> miserr = Tru E; if (! EMPTY ($ VarName)) $ this-> mstrer = trim ($ varname);

// Setting the Properties of the file Function set_file ($ INPUTNAME) {if (! Empty ($ INPUTNAME)) {$ this-> minputname = $ inputname; // Corresponding AAA, * Save Is a character, $ this-> mfiletype = $ _ files [$ inputname] ["type"]; // file upload type $ this-> mfilesize = $ _ files [$ inputname] ["size"]; // file Uploaded size $ this-> mfilename = $ _ files [$ inputname] ["name"]; // File uploaded name $ this-> mfiletmpname = $ _ files [$ inputname] ["tmp_name"]; // File upload Temporary name}}}

// Set file file name Function set_filename ($ filename) {if (! Empty ($ filename)) $ this-> mfilename = trim ($ filename);} // setup file To upload server address function set_fileuppath ($ fileuppath) { IF (Strlen ($ fileuppath) && substr ($ fileuppath, -1)! = '/') {$ fileuppath. = '/';} $ this-> mfileuppath = trim ($ fileuppath);

/ / Setting up the maximum byte of the file uploaded Function set_fileupsize ($ fileupsize) {if (! Empty ($ fileupsize) && EREG ("^ [1-9] [0-9] * $", $ fileupsize)) $ This-> mfileupsize = $ fileupsize;}

// Setting the file upload Allow type Function set_fileupty ($ fileupType) {if (! EMPTY ($ fileupType)) $ this-> mfileUpType = TRIM ($ fileupType); // Upload the type Allow

// ********************* Get area

// Get file name Function get_filename () {return $ this-> mfilename;

// Get the type of file function get_filetype () {return $ this-> mfiletype;

// Get the size of the file Function get_filesize () {return $ this-> mfilesize;}

// Temporary Function get_filetmpname () {Return $ this-> mfileTmpname;}

// Get the file to upload server address function get_fileuppath () {return $ this-> mfileuppath;}

// Get the maximum byte allowed by the file upload fullupsize () {Return $ this-> mfileupsize;}

// Get the type of file uploads allowed by file up_fileuptype () {return $ this-> mfileuptype;} // Get error code FUNCTION GET_STRERR () {Return $ this-> mstrerr;}

// ********************* CHECK area

/ ** ---------------------------------------------- - Function Name: Check_File function Description: Check the legal function of the file: Call_file () Parameters: Check_File () Parameters: Designer: GGG Date: 2004-9-1 7:06 Modifier: GGG Date: 2004-9- 1 7:06 version: 1.0 ** --------------------------------------- -------- * /

Function check_file () {$ file_tmp_name = $ this-> get_filetmpname (); // get temporary file name $ file_name = $ this-> get_filename (); // Get file name $ file_size = $ this-> get_filesize (); / / Get file size $ file_up_size = $ this-> get_fileupsize (); // Get file upload size // Check if the uploaded file exists if (Empty ($ file_tmp_name) | | $ file_tmp_name == "none" ||! File_exists $ FILE_TMP_NAME) || Empty ($ file_size)) // Do not select the file you want to upload, return {$ this-> set_strerr ("Uploaded files do not exist!"); $ this-> show_debug (); return false;} If (! is_writeable ($ this-> get_fileuppath ()) // If you uploaded to the directory can be written {$ this-> set_strerr ("Upload Directory:". $ this-> get_fileuppath (). "Does not exist or not Write, please change the directory properties first! "); $ This-> show_debug (); return false;} // Verify the legitimacy IF of the file name of the upload file ($ file_size> $ file_up_size) / / Change to lowercase {$ this -> set_strerr ("The maximum size allowed by the upload file is". $ File_up_size. "Bytes !!"); $ this-> show_debug (); return false;}

// Verify that the file type is correct if (false == $ this-> check_fileupty ()) {return false;}

/ / Verify the legitimacy of the file name of the upload file IF ($ this-> misfilelower) / / change to lowercase $ file_name = $ this-> MySTRTOLOWER ($ file_name);

// Get file names and extensions $ file_name_name = trim ($ file_name, '.')); $ File_name_ext = trim ($ this-> get_str_end ($ file_name, '.');

IF ($ this-> misfileright) // If you want to ensure that the file name can only be composed of letters, numbers, upper and lower lines, point numbers {if (! EREG ("^ [0-9a-z /._/-] ", $ file_name_ext) // Look at the legality of the extension {$ this-> set_strerr (" Upload extension: ". $ file_name_ext." Do not meet the standard, remove the extension "); $ FILE_NAME_EXT =" " // The processing here is to delete the extension $ this-> show_debug ();} if (! EREG ("^ [0-9a-z /._/-] (", $ file_name_name)) // The legality {// srand ((Double) microtime () * 1000000); $ this-> set_strerr ("Uploaded file name:". $ File_name_name. "Does not meet the standard"); $ file_name_name = Time (). $ this-> mrrorfile; //$file_name_name=rand (1,999). $ 10isystemfile; $ this-> mstrerr. = ", has been changed:" $ file_name_name. "!"; $ this-> show_debug );} $ File_name = $ file_name_name. $ File_name_ext; // Recent new file name} // File name too long process IF (Strlen ($ file_name)> $ this-> mmaxfileenamelen) // file name too long {IF (Strlen ($ file_name_ext)> $ this-> mmaxfilenamelen) // If the extension is greater than the maximum character of the allowed character, the maximum character may be small {$ this-> set_strerr ("extension length is greater than:". $ this-> mmaxfilenamelen. "!"); $ File_name_ext = Substr ($ file_name_name, 0, 5); $ this-> show_debug ();} if (Strlen ($ file_name_name)> $ this-> mmaxfilenamelen) // If the file The length that is greater than the longest character allowed, also the length of the {// file name is based on the length of the total length reduction extension, $ this-> set_strerr ("file name length is greater than:". $ This-> mmaxfilenamelen. "! "); $ File_name_name = Substr ($ file_name_name, 0, $ this-> mmaxfilenamelen-strlen ($ file_name_ext)); $ this-> show_debug ();}}

// Filter the extension Check while (List ($ K, $ V) = Each ($ this-> extfilter) {if (strstr ($ file_name_ext, $ k)) // extension contains keyword { $ this-> mstrerr. = "The extension contains keywords:" $ k. "!"; $ file_name_ext = STR_REPLACE ($ K, $ V, $ FILE_NAME_EXT); $ this-> show_debug ();}} $ FILE_NAME = $ file_name_name. $ file_name_ext; // Request to new file name // This time you have got the final file name $ this-> set_filename ($ file_name); // Reset the file name of the class member variable Return! false } // end check_file

/ ** ---------------------------------------------- - Function Name: Check_File_EXITS Function Description: Check if the upload file file has existed: CHECK_FILE_EXITS (FileName) Parameters: Return: Return File Name Designer: GGG Date: 2004-9-1 21:45 Modified: GGG Date: 2004-9-1 21:45 version: 1.0 ** ----------------------------- ------------------ * /

function Check_File_Exits ($ fileName) {// get the file name and extension name $ file_name_name = trim ($ this-> Get_Str_Head ($ fileName,) '.'); $ file_name_ext = trim ($ this-> Get_Str_End ($ fileName, ' . ')); // Watch the file to be uploaded, modify the file name IF (file_exists ($ this-> get_fileuppath (). $ Filename)) {$ this-> mstrerr. = "To upload the file The existence: "$ this-> get_fileuppath (). $ Filename."! "; $ File_name_name = substr ($ file_name_name, 0, $ this-> mmaxfilenamelen); // To prevent continuous repetition file names have become long, this truncation $ count_i = 0; while (file_exists ($ this-> Get_FileUpPath () $ file_name_name $ count_i $ file_name_ext)...) $ count_i ;. // a1 a2 a3 $ fileName = $ file_name_name $ count_i. $ file_name_ext; // Recent new file name} Return $ filename;} / ** ----------------------------- ------------------ Function Name: Check_FileUpType Features Description: Check the file upload Allow type function Description: Direct call_fileUPType () parameter: return: Return True Or False, indicating whether it is a successful designer: GGG Date: 2004-9-1 7:04 Modifier: GGG Date: 2004-9-1 7:04 version: 1.0 ** ---------- --------------------------------------- * / function check_fileupType () {$ file_up_type = $ This-> get_fileuptype (); if (EMPT Y ($ file_up_type)) // If the file type is not specified, it means all types of type {return! false;}

$ FILE_TYPE = $ this-> get_filetype (); $ array_filetype = exPlode (",", $ file_up_type); // Judgment the file type is compliant, separating for ($ count_i = 0; $ count_i set_strerr ("Please confirm the type of uploaded". $ File_up_type. "!"); $ This-> show_debug (); return false;} return! False } // end check_fileuptype / ** -------------------------------------- ------- Function Name: Upload Features Description: Upload File Function Description: The constructor of the class is used for the initialization class, which can use GggfileUpload ("AAA.GIF", "AAA.GIF"); to update the file Function to reach the first-deleted server to upload files uploaded to aaa.gif feature If you do not specify originAlFile to be used in status call functions for the first addition file: GggfileUpload ($ Keepname, $ OriginalFile) Parameters: $ keEPname Specify its parameters to indicate the file name with the keEpName after the upload file, but if the file already exists or the filename check does not pass the program, the file name will modify the original file name, set the item. Update. The program will delete the originalFile before the file is uploaded: Upload Failback Return to the file name designer after the upload success: GGG Date: 2004-9-1 5:55 Modifier: GGG Date: 2004-9 -1 5:55 version: 1.0 ** -------------------------------------- --------- * /

Function Upload ($ Keepname = ", $ OriginalFile =" ") {i (! EMPTY ($ Keepname)) {$ this-> set_filename ($ Keepname); // Change the uploaded file name $ THIS-> set_strerr (" Change the uploaded file name 1: "$ this-> get_filename ()); $ this-> show_debug ();} // check the uploaded file size type, etc., and rename the problematic file name .. if (false = = $ THIS-> Check_File ()) {// $ this-> set_strerr ("Check the uploaded file has problems: check_file"); // $ this-> show_debug (); if (! Empty ($ OriginalFile) Return $ othernalFile; Else Return "";} // Remove the original file editing status Use if (! EMPTY ($ OriginalFile) && file_exists ($ this-> get_fileuppath (). $ originalfile)) {@unlink ($ this-> GET_FILEUPPATH (). $ OriginalFile; // Delete OriginalFile file $ this-> set_strerr ("deleted:". $ This-> get_fileuppath (). $ OriginalFile. "File"); $ this-> show_debug (); } $ This-> set_filename ($ this-> get_file_exits ($ this-> get_filename ()))); // Check if the file exists, generate a new file name / * $ this-> set_file ($ inputname); $ THIS-> Set_fileuppath; $ this-> set_fileupsize ($ fileupsize); $ this-> set_fileupType ($ fileupType); Print ($ this-> minputname. "
"); Print ($ this-> mfileuptype. "
"); Prin T ($ this-> mfileupsize. "
"); Print ($ this-> mfileuppath. "
"); Print ($ this-> mfilety. "
"); print ($ this- > mfilesize. "
"); Print ($ this-> mfilename. "
"); Print ($ this-> mfiletmpname. "
"); * /

if (is_uploaded_file ($ this-> Get_FileTmpName ())) {@move_uploaded_file ($ this-> Get_FileTmpName (), $ this-> Get_FileUpPath () $ this-> Get_FileName ().);} else {$ this-> Set_StrErr ("Checking the uploaded file has a problem:" $ this-> get_filetmpname (). "Is_uploaded_file"); $ this-> show_debug (); return ";} / * Even if the copy success is also returned. I don't know what IF ($ this-> get_filetmpname (), $ this-> get_fileuppath (). $ This-> get_filename ()) == false); // Upload file {$ this-> set_strerr (" Copy the file: "$ this-> get_fileuppath (). $ This-> get_filename ()." Failure "); $ this-> show_debug (); return";} * @ @ unlink ($ this-> Get_filetmpname ()); // Delete Temporary File Return $ this-> get_filename ();}

/ * Get the character header with a character interval, the tail * / function get_str_head ($ VarName, $ SEPARATOR = '.') // Returns the name {// print ($ VarName); // Die (); $ file_len = 0; if (! ($ File_len = Strrpos ($ VarName, $ SEPARATOR))) // If the file has no extension, the file name is all file {$ file_len = Strlen ($ VarName);} $ file_name = Substr $ VarName, 0, $ file_len; // Get the upload file name Return (Substr ($ VarName, 0, $ file_len);} // get_str_head ()

Function get_str_end ($ VARNAME, $ SEPARATOR = '.') // Returns the extension of the file {$ file_len = 0; $ file_ext = ""; if ($ file_len = STRPOS ($ VARNAME, $ SEPARATOR)) // If the file Without the extension, the file name is all file, extension, empty {$ file_ext = substr ($ VARNAME, - (Strlen ($ VARNAME) - $ file_len)); // Get the extension of the upload file} Return ($ file_ext) } // get_str_end ()

// Customize the lowercase in the strings into uppercase, but does not destroy the Chinese word Function MySTRTOLOWER ($ VARNAME) {Return preg_replace ('/ [AZ] / e', "Strtolower ('// 0')" , $ Varname);

} // End class gggfileupload}

// ******************** class test // ******************** Test // ******************** class test

/ *

IF ("Submit" == $ _ post ["Command"]) {// allows multiple files to be uploaded with Text, Image, Application with comma intervals $ t = new gggfileupload ("fileename", "../ TEST / "," text, image "); // If you do not specify the allowed file type. The default is all files // $ t-> Upload ("ggg.txt", "ggg.txt"); // Delete the ggg.txt file before the file, then change the uploaded file name to GGG.txt $ NEW_FILE_NAME = $ T-> UPLOAD (); // Direct the file to the online IF (Empty ($ new_file_name)) // new_file_name is empty definitely the file upload failed {print ("file upload failed");} else {print ("Document Upload Success");} Print ($ T-> Get_FileName ()); // $ t = new gggfileupload ("filename", "../ Test /", "text, image"); // $ T-> Upload ($ keEpName = "ggg.txt", $ originalfile = "ggg.txt"); // Realize the same name override

// $ t-> set_file ("FileName1", "../ Test /", "text, image"); // Set the second file upload parameter // $ t-> UPLOAD (); // The upload of the second file.

// $ t-> set_file ("filename2"); // Set the third file upload parameter // $ T-> UPLOAD (); // Upload of the third file.

} else {// $ str = "Use C C extended php.html"; // $ str = preg_replace ('/ [az] / e', "Strtolower ('// 0')", $ STR ); // $ str = preg_replace ('/ [/ x0- / x9f] [AZ] / e', "Strtolower ('// 0')", $ STR); ECHO $ ​​Str; Print (" File upload class test </ title> <meta http-equiv = 'content-type' content = 'text / html; charset = GB2312'> </ head> <body bgcolor = '# fffff' Text = '# 000000'> <table width = '80% 'border =' 1 'cellspacing =' 0 'cellpadding =' 0 'align =' center '> <form name =' form1 'method =' post 'action = '"" $ Http_server_vars [' php_self ']. "' EncType = Multipart / Form-Data> <TR> <TD Align = 'Center'> File Upload Category Test <Input Type = 'file' name = 'filename'> < INPUT TYPE = 'Submit' Name = 'Submit2' Value = 'Uploaded File'> <input type = 'hidden' name = 'command' value = 'submit'> </> </ td> </ tr> </ form > </ TABLE> </ body> </ html> ");} * /</p> <p>// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // !!!!!!!!!!!!!!!!!!!!!</p> <p>?></p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-39439.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="39439" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.038</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = '7SYSONbxGLi_2BNa7klJHKxFyw1OFJTGEzF6B3bINg4LOd_2F1VDfZYDPksKTbQU7oIPhjxcqWy_2FgNIL1c79_2FTXjfw_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>