A simple php file Upload class

Source: Internet
Author: User
I used this file Upload class before and found many inconvenient places. Now I have made another review. do you have any shortcomings for me .? Php/** File upload class * author: multiple Cainiao * Contact Email: ki

I used this file Upload class before and found many inconvenient places.

Now I have made another review. let's help you evaluate whether there are any shortcomings.

/*
* File Upload class
* Author: many Cainiao
* Contact Email: kingerq AT msn DOT com
* Created:
* Origin:Http://blog.csdn.net/kingerq
*
* Instance:
$ F = new upfile ('./soft/', 'gif, jpg, png ');
// Upload one or more files with the same file domain name
If (isset ($ _ FILES ['Files']) {
If ($ f-> upload ('files ')){
Echo 'file uploaded successfully .';
}
}
// Upload multiple domain name files of different files
If (isset ($ _ FILES ){
Foreach ($ _ FILES as $ key => $ val)
If ($ f-> upload ($ key )){
Echo 'file uploaded successfully .';
}
}
?>
*/
Class upfile {
// Upload file information
Var $ filename;
// Reserved name
Var $ savename;
// Reserved path
Var $ savepath;
// The File pattern is limited. if it is null, the pattern is not limited.
Var $ format = '';
// Shadow mode
Var $ overwrite = 0;
/* $ Overwrite = 0 does not overwrite the same name File
* $ Overwrite = 1. the file with the same name is overwritten.
*/
// Maximum file bytes
Var $ maxsize = 210000000;
// Expand the file name
Var $ ext;
// Error code
Var $ errno = 0;
 
/* Structure function
* $ Path reserved path
* $ Format file format (separated by commas)
* $ Maxsize maximum file limit
* $ Over override parameters
*/
Function upfile ($ path, $ format = '', $ maxsize = 0, $ over = 0 ){
$ This-> savepath = substr ($ path,-1) = '/'? $ Path: $ path. '/'; // reserved path
$ This-> overwrite = $ over; // specifies whether to overwrite a file with the same name.
$ This-> maxsize =! $ Maxsize? $ This-> maxsize: $ maxsize; // maximum file size
$ This-> format = $ format;
}
 
/*
* Efficacy: detect and organize files
* $ Form file domain name
* $ File: The name of the file to be uploaded. if it is null or multiple files are uploaded, the name is automatically generated by the system.
*/
Function upload ($ form, $ file = ''){
If (! Isset ($ _ FILES [$ form]) {
$ This-> halt ('The specified file domain name does not exist. ');
} Else {
$ Filear =$ _ FILES [$ form];
}

If (! Is_writable ($ this-> savepath )){
$ This-> halt ('The specified path cannot be written. ');
}

If (is_array ($ filear ['name']) {// upload multiple files with the same file domain name
For ($ I = 0; $ I <count ($ filear ['name']); $ I ){

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.