PHP Multi-File Upload class instance, _php tutorial

Source: Internet
Author: User

PHP Multi-File Upload class instance,


This article describes the PHP multi-File upload class. Share to everyone for your reference. Specific as follows:
Copy CodeThe code is as follows: <?php
/*
PHP Multi-File Upload class
Modified: Linvo 2008-2-15
*/
Class more_file_upload{
Const file_path= '. /upfileclass/uploadfile/';
var $file _type;
var $file _type_array;
var $file _type_real_array;
var $file _type_string;
var $file _name;
var $file _size;
var $file _tmp_name;
var $file _error;
var $handledate;
var $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 ('/', ' image/gif ', ' image/jpg ', ' image/jpeg ', ' image/pjpeg ', ' image/png ');
$this-$file _type_real_array = Array (0.1, ' jpg ' =>74707370, ' gif ' =>7173, ' bmp ' =>6677, ' png ' =>807871);
$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;
$this-$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);

Perform true format validation
if ($smfiletypeflag! = False) {
$file = fopen ($this, $file _tmp_name, "RB");
$bin = fread (file, 10);
Fclose ($file);
$strInfo = @unpack ("C10chars", $bin);
$typeCode = Intval ($strInfo [' chars1 ']. $strInfo [' chars2 ']);
$smfiletypeflag = Array_search ($typeCode, $this, $file _type_real_array);
if ($smfiletypeflag = = False) {//Determine if PNG is a picture
$typeCode = Intval ($strInfo [' chars2 ']. $strInfo [' Chars3 ']. $strInfo [' CHARS4 ']);
$smfiletypeflag = Array_search ($typeCode, $this, $file _type_real_array);
if ($smfiletypeflag = = False) {//Determine if it is a JPG picture
$ $typeCode = intval ($strInfo [' chars7 ']. $strInfo [' Chars8 ']. $strInfo [' Chars9 ']. $strInfo [' CHARS10 ']);
$smfiletypeflag = Array_search ($typeCode, $this, $file _type_real_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! ';
$this->totalsize + = Intval ($smfilesize);
Self::__destruct ();
}else{
$smfilemessage = 'File upload failed! ';
Self::__destruct ();
}
}
}

$ $smfilesizeformat = $this->size_bkm ($smfilesize);
Echo '
'. $smfilename. '
'. $smfiletype. '
'. $smfilesizeformat. '
'. Smfilemessage. '
';
}

function Move_file ($mvfiletmp, $mvfilename) {//Move file
$mvfilenamearr = Explode ('. ', basename ($mvfilename));
$mvfilenamearr [0] = $this->rand_string ();
$mvfilename = Implode ('. ', $mvfilenamearr);

if (Is_uploaded_file ($mvfiletmp)) {
$uploadfile = Self::file_path. " $mvfilename ";
$result = Move_uploaded_file ($mvfiletmp, $uploadfile);
return $result;
}
}

function rand_string () {
$string = MD5 (Uniqid (rand (). Microtime ()));
return $string;
}

function size_bkm ($size) {//B/KB/MB unit conversion
if ($size < 1024)
{
$size _bkm = (string) $size. "B";
}
ElseIf ($size < (1024 * 1024))
{
$size _bkm = Number_format ((double) ($size/1024), 1). "KB";
}else
{
$size _bkm = Number_format ((double) ($size/(1024*1024)), 1). " MB ";
}
return $size _bkm;
}
}
?>

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/963834.html www.bkjia.com true http://www.bkjia.com/PHPjc/963834.html techarticle PHP Multi-File Upload class instance, this article describes the PHP multi-File upload class. Share to everyone for your reference. The following: Copy code code as follows: PHP/* PHP Multi-File Upload class repair ...

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