Multiple file uploads

Source: Internet
Author: User

<meta charset= "Utf-8"/>
<?php
Class upload
{
Public $files;
Public $seterror;
Public $allowtype;
Public $filetype;
Public $typeerror;
public $path;
Public $SUCC = 0;
Public $filenewname;
function __construct ($files, $path)
{
$this->path= $path;
$this->files= $files;
$this->seterror=1;
$this->allowtype=array ("JPG", "gif", "JPG", "PNG");
$this->filetype=array ();
$this->filenewname=array ();
if (Is_array ($_files[$files [' name ']))
{
foreach ($_files[$files] [' name '] as $key = $names)
{
$file _ex=explode (".", $names);//split into arrays
$this->filetype[$key]= $file _ex[count ($file _ex)-1];
$this->filenewname[$key]= $this->path.time (). $key. ".". $this->filetype[$key];
}
foreach ($this->filetype as $key = $type)
{
if (!in_array ($type, $this->allowtype))
{
$this->typeerror= $key +1;
$this->seterror= ". $this->typeerror." Picture type does not meet the requirements ";
Echo $this->seterror;
Exit
}
}
foreach ($_files[$files [' Error '] as $val)
{
if ($val!=0)
{
Switch ($val)
{
Case 1:;
Case 2: $this->seterror= "Upload the file too large, the maximum can upload 2M";
Case 3: $this->seterror= "file is only partially uploaded";
Case 4: $this->seterror= "File not uploaded";
Case 6: $this->seterror= "temporary folder not found";
Case 7: $this->seterror= "file write Failed";
}
Echo $this->seterror;
Exit
}
}

}
if (!file_exists ($path))
{
mkdir ($path, 0777);
}
if ($this->seterror==1)
{
$this->move_file ();
}

}
Private Function Move_file ()
{

foreach ($_files[$this->files][' Tmp_name ') as $key = $tmp)
{
if (Move_uploaded_file ($tmp, $this->filenewname[$key]))
{
$this->succ+=1;
}
}
if ($this->succ==count ($_files[$this->files][' name '))
{
echo "all uploads successfully";
}
}
}



?>

Multiple file uploads

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.