PHP Upload class, share with you, please forgive me for your shortcomings! How to deal with it-php Tutorial

Source: Internet
Author: User
PHP Upload class, share with you, please forgive me for your shortcomings! Thank you for your understanding! PHPcode *** file Upload class kangyangyang2010-06-07 * $ loadfile file domain of the file to be uploaded * $ loadpath file storage path * $ loadhold keep File original name * $ loadsize file size limit default is 2048KB * $ the loadtype file type is limited to the PHP Upload class, sorry for your shortcomings!
Thank you for your understanding!

PHP code
  /*** File Upload class kangyangyang 2010-06-07 * $ loadfile file to be uploaded * $ loadpath file storage path * $ loadhold File original name * $ loadsize file size limit/default is 2048KB * $ loadtype file type limit // jpg is supported by default | jpeg | gif | png | txt | rar | zip **/class uploadfile {private $ loadfile; private $ loadpath; private $ loadsize; private $ loadtype; private $ loadhold = false; private $ chkfile = true; private $ file_name; private $ extend_type; private $ set_name; private $ set_size; private $ Set_path; private $ set_create_name; private $ get_error; // constructors function _ construct ($ loadfile, $ loadpath, $ loadhold = false, $ loadsize = "2097152 ", $ loadtype = "jpg | jpeg | gif | png | txt | rar | zip") {$ this-> loadfile = $ loadfile; $ this-> loadpath = $ loadpath; $ this-> loadsize = $ loadsize; $ this-> loadtype = $ loadtype; $ this-> loadhold = $ loadhold; $ this-> filecheck ();} // File upload function filecheck () {$ filename = $ _ FILES [$ thi S-> loadfile] ['name']; // file name $ filetype = $ _ FILES [$ this-> loadfile] ['type']; // File Type $ filesize = $ _ FILES [$ this-> loadfile] ['size']; // File Size $ filepath = $ _ FILES [$ this-> loadfile] ['tmp _ name']; // temporary file $ fileerror = $ _ FILES [$ this-> loadfile] ['error']; // error code if ($ fileerror <= 0 & $ filename! = "") {If ($ this-> loadsize >=$ filesize) {$ this-> set_size = $ filesize; $ ext = explode (". ", $ filename); $ this-> set_name = $ ext; $ ext_type = strtolower ($ ext [count ($ ext)-1]); $ this-> extend_type = $ ext_type; $ chk_type = explode ("|", $ this-> loadtype); if (in_array ($ ext_type, $ chk_type )) {$ f_path = $ this-> get_folder (); $ this-> set_create_name = $ createname = time (). rand (1,9999); $ this-> file_name = $ createname. ". ". $ Ext_type; if ($ this-> loadhold) {$ file_path = $ f_path. $ filename; $ this-> set_path = $ file_path;} else {$ file_path = $ f_path. $ this-> file_name; $ this-> set_path = $ file_path;} $ ckfile = move_uploaded_file ($ filepath, $ file_path); if (! $ Ckfile) {$ this-> chefile = false ;}} else {$ this-> chkfile = false ;}} else {$ this-> chkfile = false ;}} else {$ this-> chkfile = false; $ this-> get_error = $ fileerror;} // generated file name function get_CreateName () {if ($ this-> CheckFile () {if (! $ This-> loadhold) {return $ this-> set_create_name ;}}// return the folder path function get_folder () {if ($ this-> CheckFile ()) {if (! File_exists ($ this-> loadpath) {mkdir ($ this-> loadpath, 0777, true); chmod ($ this-> loadpath, 0777 );} return $ this-> loadpath; }}// file extension function get_type () {if ($ this-> CheckFile () {return $ this-> extend_type ;}} // file name "does not include the extension" function get_name () {if ($ this-> CheckFile () {$ filename = $ this-> set_name; unset ($ filename [count ($ filename)-1]); return implode (". ", $ filename) ;}// returns the file size function get_size () {if ($ this-> CheckFile () {return $ this-> set_size ;}} // return the full file path function get_path () {if ($ this-> CheckFile () {return $ this-> set_path ;}} // whether the file is successfully uploaded function CheckFile () {return $ this-> chkfile;} // Obtain the error code function get_error () {if ($ this-> CheckFile ()) {return $ this-> get_error ;}}}


------ Solution --------------------
Yes, thank you.
------ Solution --------------------

------ Solution --------------------
Good, favorites
------ Solution --------------------
Taobao.com

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.