input 限制 上传文件类型

本文介绍了如何通过HTML的`accept`属性来限定文件上传的类型,包括常见的图像、文档及多媒体文件格式,并提供了具体的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<tr>
   <td colspan="5">  款式图片<input  type="file" accept="image/*"  name="img" id="img"></td>

</tr>
<tr>
    <td colspan="2"> 作业指导书 <input  type="file" accept="application/pdf"  name="work_attach" id="work_attach"></td>
  {if !empty($data.DocURL)}    <td  colspan="3"> <br/><a href="{$data.DocURL}" download="作业指导书">作业指导书下载</a></td>{/if}
</tr>



在文件上传中使用 accept 属性,本例中的输入字段可以接受 GIF 和 JPEG 两种图像:

<form>
  <input type="file" name="pic" id="pic" accept="image/gif, image/jpeg" />
</form>
如果不限制图像的格式,可以写为:accept="image/*"。

文件类型选择

1.accept=”application/msexcel” 2.accept=”application/msword” 3.accept=”application/pdf” 4.accept=”application/poscript” 5.accept=”application/rtf” 6.accept=”application/x-zip-compressed” 7.accept=”audio/basic” 8.accept=”audio/x-aiff” 9.accept=”audio/x-mpeg” 10.accept=”audio/x-pn/realaudio” 11.accept=”audio/x-waw” 12.accept=”image/gif” 13.accept=”image/jpeg” 14.accept=”image/tiff” 15.accept=”image/x-ms-bmp” 16.accept=”image/x-photo-cd” 17.accept=”image/x-png” 18.accept=”image/x-portablebitmap” 19.accept=”image/x-portable-greymap” 20.accept=”image/x-portable-pixmap” 21.accept=”image/x-rgb” 22.accept=”text/html” 23.accept=”text/plain” 24.accept=”video/quicktime” 25.accept=”video/x-mpeg2” 26.accept=”video/x-msvideo”

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值