The fileclass.php file code is as follows:
<?php
Class more_file_upload{
Const file_path= '.. /filehandle/uploadfile/';
var $file _type;
var $file _type_array;
var $file _type_string;
var $file _name;
var $file _size;
var $file _tmp_name;
var $file _error;
var $handledate;
static $totalsize = 0;
function __construct ($file _name, $file _error, $file _size, $file _tmp_name, $file _type) {
$this->handledate=date (' m-d-y ');
if (!empty ($file _name)) {
$this->file_name= $file _name;
$this->file_error= $file _error;
$this->file_size= $file _size;
$this->file_tmp_name= $file _tmp_name;
$this->file_type= $file _type;
$this->file_type_array=array (' Text/plain ', ' image/gif ', ' image/jpg ', ' text/html ', ' image/pjpeg ', ' image/png ', ' Application/msword ', ' application/pdf ');
$this->show_execute_message ($this->file_error, $this->file_name, $this->file_type, $this->file_ size);
}
}
function __destruct () {
$this->file_name = NULL;
$this->file_error = NULL;
$this->file_size = NULL;
$this->file_tmp_name = NULL;
$this->file_type = NULL;
Self:: $totalsize = 0;
}
function Show_execute_message ($smfileerror, $smfilename, $smfiletype, $smfilesize) {
if ($smfileerror >0) {
Switch ($smfileerror) {
Case 1: $smfilemessage = ' <strong> file exceeds the contract size of the server! </strong> ';
Case 2: $smfilemessage = ' <strong> file exceeds the specified file size! </strong> ';
Case 3: $smfilemessage = ' <strong> file only uploaded part! </strong> ';
Case 4:echo "$this->file_name". File upload failed! <br/> ';
}
Self::__destruct ();
}else{
$smfiletypeflag =array_search ($smfiletype, $this->file_type_array);
if ($smfiletypeflag = = False) {
$smfilemessage = ' <strong> file type is wrong, please verify! </strong> ';
Self::__destruct ();
}else{
$resflag = $this->move_file ($this->file_tmp_name, $this->file_name);
if ($resflag = = 1) {
$smfilemessage = ' File Upload success! ';
Self:: $totalsize +=intval ($smfilesize);
Self::__destruct ();
}else{
$smfilemessage = ' <strong> file upload failed! </strong> ';
Self::__destruct ();
}
}
}
$smfilesize = $smfilesize/1024;
$smfilesizeformat =sprintf ('%01d ', $smfilesize);
Echo ' <tr>
<TD align= "left" > '. $smfilename. ' </td>
<TD align= "center" > '. $smfiletype. ' </td>
<TD align= "center" > '. $smfilesizeformat. ' </td>
<TD align= "center" > '. $smfilemessage. ' </td>
</tr> ';
}
function Move_file ($mvfiletmp, $mvfilename) {//Move file
$mvfilenamearr =explode ('. ', basename ($mvfilename));
$mvtime =mktime ();
$mvfilenamearr [0]= $this->rand_string (10). " $mvtime ";
$mvfilename =implode ('. ', $mvfilenamearr);
if (Is_uploaded_file ($mvfiletmp)) {
$uploadfile =self::file_path. " $mvfilename ";
$result =move_uploaded_file ($mvfiletmp, $uploadfile);
return $result;
}
}
function rand_string ($len, $chars = ' ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ') {//specified range of randomly extracted characters
$string = ';
for ($i = 0; $i < $len; $i + +) {
$pos = rand (0, strlen ($chars)-1);
$string. = $chars {$pos};
}
return $string;
}
}
Echo ' <table width= "90%" border= "1" cellpadding= "0" align= "center" cellspacing= "2" >;
Echo ' <tr>
<TD align= "center" > FileName </td>
<TD align= "Center" > File Type </td>
<TD align= "Center" > File Size (KB) </td>
<TD align= "center" > Implementation Results </td>
</tr> ';
for ($i =0; $i <count ($_files[' userfile '); $i + +) {
$filename [$i]=$_files[' userfile '] [' name '] [$i];
$fileerror [$i]=$_files[' userfile '] [' ERROR '] [$i];
$filesize [$i]=$_files[' userfile '] [' size '] [$i];
$filetmpname [$i]=$_files[' userfile '] [' tmp_name '] [$i];
$filetype [$i]=$_files[' userfile '] [' type '] [$i];
$filetemp =new more_file_upload ("$filename [$i]", "$fileerror [$i]", "$filesize [$i]", "$filetmpname [$i]", "$filetype [$ I] ");
}
Echo ' </table> ';
Echo ' <a href= "upfile.html" > Continue uploading </a> <a href= "index.php" > Return home </a> ';
?>
Here is a third file, which is the index.php display file.