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 ){