21,887
社区成员
发帖
与我相关
我的任务
分享
$arrAttachment = $_FILES['picfile'];
if(is_array($arrAttachment))
{
//获得系统路径,如果没有则建立
$tmpDir = _ATTACH_DIR . date('ymd') . "/" . $id . "/";
if(!is_dir($tmpDir))
{
_mkdir($tmpDir);
}
$arrFileName = $_FILES['attachments']['name'];
$arrTmpName = $_FILES['attachments']['tmp_name'];
$arrError = $_FILES['attachments']['error'];
foreach($arrFileName as $key=>$value)
{
if($arrError[$key] != 0)
{
echo $arrError[$key];
continue;
}
$strExtend = "." . pathinfo($value, PATHINFO_EXTENSION);
$strSrcFileName = $arrTmpName[$key];
$strClientFileName = $arrFileName[$key];
if(preg_match("/\.(exe|php|js|htm|html|bat)/i", $strExtend))
{
echo $strExtend . "<br/>";
//unlink($strSrcFileName);
continue;
}
$strFileName = getRandomName() . $strExtend;
$strDestName = $tmpDir . $strFileName;
move_uploaded_file($strSrcFileName, $strDestName);
//入库
}
}
function getRandomName()
{
$strTime = date('YmdHis') . rand(1,1000);
return md5($strTime);
}