save_img($_FILES);
function save_img($file)
{
$arr = '';
foreach ($file as $key => $value)
{
$ss = save_img_true($value);
if(!is_array($ss))
{
$arr[] = $ss;
}
}
return $arr;
}
function save_img_true($file)
{
// 判断文件类型,大小
if(($file['type'] == 'image/gif' || $file['type'] == 'image/jpeg' || $file['type']== 'image/pjpeg' || $file['type'] == 'image/png') && $file['size'] < 200000)
{
if($file['error'] > 0)
{
return array(-1,$file['name'].'上传失败');
}else{
$end = substr($file['name'],strripos($file['name'],'.'));
$arr = array_merge(range(1,100,2),range('a','z'));
// 文件上传路径
$path = './image/';
$name = time().$arr[array_rand($arr)].$arr[array_rand($arr)].$end;
move_uploaded_file($file['tmp_name'],$path.$name);
return $name;
}
}
}
转载于:https://my.oschina.net/myzyq/blog/491534