PHP multi-File Upload code two _php tutorial

Source: Internet
Author: User
The fileclass.php file code is as follows:

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 = 'file exceeds the contract size of the server! '; break;
Case 2: $smfilemessage = 'file exceeds the specified file size! '; break;
Case 3: $smfilemessage = 'only part of the file was uploaded! '; break;
Case 4:echo "$this->file_name". File upload failed!
'; break;
}
Self::__destruct ();
}else{
$smfiletypeflag =array_search ($smfiletype, $this->file_type_array);
if ($smfiletypeflag = = False) {
$smfilemessage = 'The file type is wrong, please verify! ';
Self::__destruct ();
}else{
$resflag = $this->move_file ($this->file_tmp_name, $this->file_name);
if ($resflag = = 1) {
$smfilemessage = ' File upload succeeded! ';
Self:: $totalsize +=intval ($smfilesize);
Self::__destruct ();
}else{
$smfilemessage = 'File upload failed! ';
Self::__destruct ();
}
}
}
$smfilesize = $smfilesize/1024;
$smfilesizeformat =sprintf ('%01d ', $smfilesize);
Echo '
'. $smfilename. '
'. $smfiletype. '
'. $smfilesizeformat. '
'. $smfilemessage. '
';
}

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 ') {//randomly extracts characters within the specified range
$string = ";
for ($i = 0; $i < $len; $i + +) {
$pos = rand (0, strlen ($chars)-1);
$string. = $chars {$pos};
}
return $string;
}
}
Echo '









<>









'; Echo ' ' For ($i =0; $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 '
Filename File type File Size (KB) Execution results
';
Echo ' Continue uploading back to homepage ';
?>

Here is a third file, that is, index.php display files.

http://www.bkjia.com/PHPjc/632024.html www.bkjia.com true http://www.bkjia.com/PHPjc/632024.html techarticle 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 _na ...

  • 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.