<?php
/**
* 构建文件上传的基本信息
*/
function builderInfo()
{
$index = 0;
foreach ($_FILES as $item){
//多个
if (is_array($item[‘name‘])){
foreach ($item[‘error‘] as $key => $error){
if($error === UPLOAD_ERR_OK){
$file[$key][‘name‘] = $item[‘name‘][$key];
$file[$key][‘type‘] = $item[‘type‘][$key];
$file[$key][‘size‘] = $item[‘size‘][$key];
$file[$key][‘error‘] = $item[‘error‘][$key];
$file[$key][‘tmp_name‘] = $item[‘tmp_name‘][$key];
$index++;
}
}
}else{
if($item[‘error‘] === UPLOAD_ERR_OK){
$files[] =$item;
}
}
}
return $files;
}
/**
* 上传文件
*/
function upload()
{
$files = builderInfo();
foreach ($files as $file){
$filename = uuid() . ‘.‘ . getExtension($file[‘name‘]);
move_uploaded_file($file[‘tmp_name‘, $directory . ‘/‘ . $filename]);
}
}