PHP multiple File Upload code two

Source: Internet
Author: User
Tags file upload

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>
&LT;TD align= "left" > '. $smfilename. ' </td>
&LT;TD align= "center" > '. $smfiletype. ' </td>
&LT;TD align= "center" > '. $smfilesizeformat. ' </td>
&LT;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>
&LT;TD align= "center" > FileName </td>
&LT;TD align= "Center" > File Type </td>
&LT;TD align= "Center" > File Size (KB) </td>
&LT;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.

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.