Common php File Upload class-Multifile upload-PHP source code

Source: Internet
Author: User
Ec (2); & lt ;? PhpclassMy_Lib_upfile {& nbsp; var $ upfile, $ upfile_name, $ upfile_size; & nbsp; # $ upfile temporary file name $ _ FILES [tmp_name], $ upfile_name file name $ _ FILES [name], $ upfile_size file size $ _ FILES [size]; & script ec (2); script

Class My_Lib_upfile {

Var $ upfile, $ upfile_name, $ upfile_size;
# $ Upfile temporary file name $ _ FILES ['tmp _ name'], $ upfile_name file name $ _ FILES ['name'], $ upfile_size file size $ _ FILES ['SIZE'];

Var $ new_upfile_name; # Name of the uploaded file;
Var $ fleth, $ fileExtent; # file extension (type );
Var $ f1, $ f2, $ f3; # file storage path (multilevel) upfiles/2008-01/08 /;
Var $ filename; # file (with Path );
Var $ filepath; # The relative path is used to delete objects;
Var $ maxSize, $ File_type; # the type of the file to be uploaded;

Var $ BuildFile, $ newFile, $ File_width, $ File_height, $ rate;

Function upfileclass ($ upfile, $ upfile_name, $ upfile_size ){
$ This-> upfile = $ upfile;
$ This-> upfile_name = $ upfile_name;
$ This-> upfile_size = $ upfile_size;
$ This-> new_upfile_name = $ this-> CreateNewFilename ($ this-> upfile_name );
$ This-> f1 = "public/upload/images ";
$ This-> f2 = $ this-> f1. "/". date ('y'). "-". date ('M ');
$ This-> f3 = $ this-> f2. "/". date ('D ');
$ This-> filename = $ this-> f3. "/". $ this-> new_upfile_name;
$ This-> maxSize = 5000*1024; # file size: KB
$ This-> File_type = "gif/jpg/jpeg/png/bmp"; # types of files that can be uploaded
}

# Create a new file name (original file name)
Function CreateNewFilename ($ file_name ){
$ This-> fleth = explode (".", $ file_name );
$ This-> fileExtent = $ this-> fleth [(int) count ($ this-> fleth)-1]; # obtain the file suffix;
$ Tmps tutorial tr = date ('ymmd'). rand (0, time (). ".". $ this-> fileExtent; # create a new file name;
Return $ tmpstr;
}

# Check whether the file type is correct
Function chk_fileExtent (){
$ IwTrue = 0;
$ Fle = explode ("/", $ this-> File_type );
For ($ I = 0; $ I <count ($ fle); $ I ++ ){
If ($ this-> fileExtent ==$ fle [$ I]) {
$ IwTrue = (int) $ iwTrue + 1;
}
}
If ($ iwTrue = 0 ){
$ This-> msg ("the file does not match". $ this-> File_type. "format! ");
}
}

# Prompt the error message and terminate the operation
Function msg ($ Error ){
Echo"

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.