Learn to upload PHP files

Source: Internet
Author: User
Up. class. php & lt ;? Phpclassup {public $ f; // indicates $ _ FILES [xx] public $ s; // The size of the uploaded file is public $ n; // specifies whether the file name is public $ d; // specify the folder function _ construct ($ f, $ s = 1, $ n = false, $ d

Up. class. php

 

F = $ f; $ this-> s = $ s * 1000000; $ this-> n = $ n; $ this-> d = $ d; $ this-> loading ();} function loading () {$ this-> fsize (); $ this-> ftype (); $ this-> fmv ();} function fname () {if ($ this-> n) {return $ this-> n. $ this-> ftype ();} else {return time (). rand (111,999 ). $ this-> ftype () ;}} function fdir () {if ($ this-> d) {// Determine whether the user specifies the folder name if (! Is_dir ($ this-> d) {// determines whether the specified folder name contains mkdir ($ this-> d);} return $ this-> d. "/";} else {if (! Is_dir (date ("Ymd") {mkdir (date ("Ymd");} return date ("Ymd "). "/" ;}}// end fdir function fsize () {if ($ this-> f ['size']> $ this-> s) {echo "file size exceeded"; exit () ;}else {return true ;}} function ftype () {switch ($ this-> f ['type']) {case "image/x-png": $ OK = ". png "; break; case" image/png ": $ OK = ". png "; break; case" application/pdf ": $ OK = ". pdf "; break; case" image/pjpeg ": $ OK = ". jpg "; break; case" image/jpeg ": $ OK = ". jpg "; break; Case "image/jpg": $ OK = ". jpg "; break; default: $ OK = false; break;} if ($ OK) {return $ OK;} else {echo" incorrect file type "; exit () ;}} function fmv () {move_uploaded_file ($ this-> f ['tmp _ name'], $ this-> fdir (). $ this-> fname () ;}}?> Upload files using test. php$ V) {new up ($ _ FILES [$ id]) ;}}?>

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.