<?php
if (is_array($_FILES['file']['name'])){
foreach ($_FILES['file']['error'] as $key => $error){
if ($error == UPLOAD_ERR_OK){
//获取当前上传文件的名称(原始名称)
$filename = $_FILES['file']['name'][$key];
//获取当前上传文件的扩展名
$extension = strtolower(substr($filename, strrpos($filename, '.' ) + 1));
//生成唯一的主文件名
$mainName = md5_(uniqid(microtime() . mt_rand()));
//再前二者结合成新的文件名
$filename = $mainName . '.' . $extension;
//移动临时文件到新位置且赋予新名称
move_uploaded_file($_FILES['file']['tmp_name'][$key], $filename);
}
}
}else {
if ($_FILES['file']['error'] == UPLOAD_ERR_OK){
//原始名称
$filename = $_FILES['file']['name'];
//获取文件的扩展名
$position = strrpos($filename, '.') + 1;
$extension = substr($filename, $position);
//生成唯一主文件名
$mainName = md5(uniqid(microtime() . mt_rand()));
//将前两者结合成新的文件名
$filename = $mainName . '.' . $extension;
//移动上传的临时文件到新位置并命名新名称
move_uploaded_file($_FILES['file']['tmp_name'], $filename);
}
}