<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