php批量上传文件

前台显示代码:

[php]<input type=’file’ name=’filelist[]’ id=’filelist[]’ accept=’image/gif,image/jpeg,image/png,pdf,doc,docx,xls,xlsx’>[/php]

PHP处理文件代码:

[php]for ($i=0;$i<count($_FILES["filelist"][name]);$i++){

//*******************相片–開始*******************

$idcard_photo_name = $_FILES["filelist"]["name"][$i];
$idcard_photo_size = $_FILES["filelist"]["size"][$i];
$idcard_photo_exe = substr($idcard_photo_name,strrpos($idcard_photo_name,’.’),strlen($idcard_photo_name)-strrpos($idcard_photo_name,’.’));

if($idcard_photo_exe == ".jpg" || $idcard_photo_exe == ".jpeg" || $idcard_photo_exe == ".gif" || $idcard_photo_exe == ".png" || $idcard_photo_exe == ".JPG" || $idcard_photo_exe == ".JPEG" || $idcard_photo_exe == ".GIF" || $idcard_photo_exe == ".PNG" || $idcard_photo_exe == "" || $idcard_photo_exe == ".pdf" || $idcard_photo_exe == ".doc" || $idcard_photo_exe == ".docx" || $idcard_photo_exe == ".xls"|| $idcard_photo_exe == ".xlsx" )
{
if($idcard_photo_size > 10000*1024)
{
echo "<script language=’javascript’>alert(‘病歷不能大於10MB’);history.go(-1);</script>";
}
else
{
if(!empty($idcard_photo_exe))
$IDCardPhoto=getRandomNum().$idcard_photo_exe;

if(!empty($idcard_photo_name))
{
$idcard_photo_big=$UploadPath."/bingli/".$IDCardPhoto;
$idcard_photo_tmp = $_FILES["filelist"][‘tmp_name’][$i];
if(copy($idcard_photo_tmp,$idcard_photo_big))
{
unlink($idcard_photo_tmp);

$sal="insert into htx_bingli_img (blid,img) values (".$UserID.",’".$IDCardPhoto."’)";
$quer=$db->query($sal);

}

}
}
}
else
{
echo "<script language=’javascript’>alert(‘病歷類型只能是: jpg/jpeg/gif/png/pdf/doc/docx/xls/xlsx’);history.go(-1);</script>";
}
//*******************相片–結束*******************

}[/php]

动态添加文件选择控件代码:
JS代码:

[php]<script language="javascript">
//<!–动态添加文件选择控件–>
function AddRow()
{
var eNewRow = tblData.insertRow();
for (var i=0;i<1;i++)
{
var eNewCell = eNewRow.insertCell();
eNewCell.innerHTML = "<input type=’file’ name=’filelist[]’ id=’filelist[]’ accept=’image/gif,image/jpeg,image/png,pdf,doc,docx,xls,xlsx’>";
}
}
// –>
</script> [/php]

html代码:

[php]<table id="tblData" width="400" border="0">

</table> [/php]

您可能还喜欢...

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注