A newly written file Upload class. Welcome to comments & lt; html & gt; & lt; head & gt; & lt; title & gt; Upload file Form & lt;/title & gt; & lt; /head & gt; & lt; body & gt; & lt; form & nbsp; enctype = "a file Upload class just written by mult. Comments
Upload file Form
Define (UPLOAD_DIR, 'd: \ AppServ \ www \ test \ upload \\');
Define (UPLOAD_WEB_DIR, '\ test \ upload \\');
Class upload_file_class {
Var $ input_name; // name of the uploaded file
Var $ max_size; // The maximum upload size, in kb.
Var $ allow_ext; // allowed extension
Var $ err_info; // error message
/**
* Constructor
*
* @ Param $ input_name
* @ Param $ max_size
* @ Param $ allow_ext
* @ Return
*/
Function _ construct ($ input_name, $ max_size = 1024, $ allow_ext = array ('jpg ', 'PNG', 'GIF ')){
$ This-> input_name = $ input_name;
$ This-> max_size = $ max_size;
$ This-> allow_ext = $ allow_ext;
$ This-> err_info_arr = array (
1 => 'The size of the uploaded file exceeds the ini value ',
2 => 'The size of the uploaded file exceeds the maximum size set in the form ',
3 => 'Only part of the file is upload ',
4 => 'No file is upload ',
5 => 'The size of the uploaded file exceeds the allowed value ',
6 => 'File type not allowed to be uploaded ',
7 => 'failed to create the directory. check whether you have the permission to create the directory ',
8 => 'File creation failed. please try again. ',
9 => 'File Upload error. please try again. '
);
}
/**
* File Upload
*
* @ Return $ file_path_arr array of successfully uploaded file paths
*/
Public function upload (){
Global $ _ FILES;
If (! Is_array ($ this-> input_name) $ this-> input_name = array ($ this-> input_name );
$ File_path_arr = array ();
Foreach ($ this-> input_name as $ k => $ input_name ){
$ __F = $ _ FILES [$ input_name];
If (! Empty ($ __f )){
If ($ __f ['error']> 0 ){
// Client Upload error
$ This-> set_err ($ __f ['error']);
}
Else {
$ __F ['size'] =__ F ['size']/1024;
If ($ this-> max_size >=__ __ F ['size']) {
If ($ this-> check_ext ($ __f ['name']) {
$ Save_dir_info = $ this-> check_dir ();
If ($ save_dir_info ){
$ Rand_num = date ('ymdhis '). rand (0, 000 );
$ Ext = $ this-> get_img_ext ($ __f ['name']);
$ New_file_name = $ rand_num. ". {$ ext }";
$ Full_path = $ save_dir_info ['full _ dir']. $ new_file_name;
$ Full_web_path = $ save_dir_info ['full _ web_dir ']. $ new_file_name;
If (! File_exists ($ full_path )){
If (move_uploaded_file ($ __f ['tmp _ name'], $ full_path )){