首页 > 其他分享 >File的accept的属性

File的accept的属性

时间:2023-03-13 16:37:00浏览次数:44  
标签:文件 vnd ms image accept application File 上传 属性

上传图片的

<input id="AttachedUrl"
required
name="AttachedUrl" accept="image/gif,image/jpeg,image/jpg,image/png,image/bmp" type="file" class="form-control" />

 对于上传图片的属性的框的问题,对于不同的属性,进行分割的时候使用,

 

 

对于上传Excel文件的问题

<input id="File1" type="file" class="form-control"
accept="application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
name="excelFile" />

 

 

其他关于accept的问题

HTML5的 input:file上传类型控制

2014年8月29日 331172次浏览

一、input:file属性

属性值有以下几个比较常用:

accept:表示可以选择的文件MIME类型,多个MIME类型用英文逗号分开,常用的MIME类型见下表。

multiple:是否可以选择多个文件,多个文件时其value值为第一个文件的虚拟路径。

1、accept

只能选择png和gif图片

<input id="fileId1" type="file" accept="image/png,image/gif" name="file" />

2、multiple

多文件上传

<input id="fileId2" type="file" multiple="multiple" name="file" />

3、常用MIME类型

后缀名       MIME名称
*.3gpp    audio/3gpp, video/3gpp
*.ac3    audio/ac3
*.asf       allpication/vnd.ms-asf
*.au           audio/basic
*.css           text/css
*.csv           text/csv
*.doc    application/msword    
*.dot    application/msword    
*.dtd    application/xml-dtd    
*.dwg    image/vnd.dwg    
*.dxf      image/vnd.dxf
*.gif            image/gif    
*.htm    text/html    
*.html    text/html    
*.jp2            image/jp2    
*.jpe       image/jpeg
*.jpeg    image/jpeg
*.jpg          image/jpeg    
*.js       text/javascript, application/javascript    
*.json    application/json    
*.mp2    audio/mpeg, video/mpeg    
*.mp3    audio/mpeg    
*.mp4    audio/mp4, video/mp4    
*.mpeg    video/mpeg    
*.mpg    video/mpeg    
*.mpp    application/vnd.ms-project    
*.ogg    application/ogg, audio/ogg    
*.pdf    application/pdf    
*.png    image/png    
*.pot    application/vnd.ms-powerpoint    
*.pps    application/vnd.ms-powerpoint    
*.ppt    application/vnd.ms-powerpoint    
*.rtf            application/rtf, text/rtf    
*.svf           image/vnd.svf    
*.tif         image/tiff    
*.tiff       image/tiff    
*.txt           text/plain    
*.wdb    application/vnd.ms-works    
*.wps    application/vnd.ms-works    
*.xhtml    application/xhtml+xml    
*.xlc      application/vnd.ms-excel    
*.xlm    application/vnd.ms-excel    
*.xls           application/vnd.ms-excel    
*.xlt      application/vnd.ms-excel    
*.xlw      application/vnd.ms-excel    
*.xml    text/xml, application/xml    
*.zip            aplication/zip    
*.xlsx     application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

二、样式美化

请看博客:css input[type=file] 样式美化,input上传按钮美化 http://www.haorooms.com/post/css_input_uploadmh

三、AJAX上传文件

在说到ajax上传文件。ajax上传的时候,需要获得input:file选择的文件(可能为多个文件),获取其文件列表为:

// input标签的files属性
document.querySelector("#fileId").files
// 返回的是一个文件列表数组

获得的文件列表,然后遍历插入到表单数据当中。即:

// 获得上传文件DOM对象
var oFiles = document.querySelector("#fileId");


// 实例化一个表单数据对象
var formData = new FormData();



// 遍历图片文件列表,插入到表单数据中
for (var i = 0, file; file = oFiles[i]; i++) {
    // 文件名称,文件对象
    formData.append(file.name, file);
}

获得表单数据之后,就可以用ajax的POST上传。

// 实例化一个AJAX对象
var xhr = new XMLHttpRequest();
xhr.onload = function() {
    alert("上传成功!");
}
xhr.open("POST", "upload.php", true);

// 发送表单数据
xhr.send(formData);

上传到服务器之后,获取到文件列表为:

Array
(
    [jpg_jpg] => Array
        (
            [name] => jpg.jpg
            [type] => image/jpeg
            [tmp_name] => D:\xampp\tmp\phpA595.tmp
            [error] => 0
            [size] => 133363
        )

    [png_png] => Array
        (
            [name] => png.png
            [type] => image/png
            [tmp_name] => D:\xampp\tmp\phpA5A6.tmp
            [error] => 0
            [size] => 1214628
        )

)

在服务端循环遍历这个数组就可以上传文件了。

标签:文件,vnd,ms,image,accept,application,File,上传,属性
From: https://www.cnblogs.com/sexintercourse/p/17211844.html

相关文章

  • SQL SERVER PROFILER监听指定数据库
    SQLSERVERPROFILER监听指定数据库SQLServerProfiler监听指定数据库查询数据库IDSQLServerProfiler工具启动监听指定id的数据库 SQLSERVERPROFILER......
  • 20230313-VUE-VUE新建项目报错Error: The package.json file at 'C:\Users\Administ
    缺少package.json文件npminit-y初始化一个文件 ......
  • IO流、File文件操作、文件操作
    文件操作1.File类File类是用于操作文件和文件夹的一种方式,可以针对文件和文件夹完成增删改查操作。路径分隔符:针对windows默认采用\作为分隔符Linux、unix系统默认......
  • Linux操作系统file命令 – 识别文件类型
    前言file命令用来识别文件类型,也可用来辨别一些文件的编码格式。(是通过查看文件的头部信息来获取文件类型,而不是像Windows通过扩展名来确定文件类型的)语法file[参数]......
  • 6.S081 lab9 file system
    #Largefiles第一个实验还算比较简单的,不过测试样例好像不是很严格,刚开始我做完后拿去跑测试样例,过了,但其实代码是有点小问题的,然后这些问题就导致了我第二个实验symlin......
  • Django匿名用户的属性
    fromdjango.contrib.auth.modelsimportAnonymousUserclassAnonymousUser:id=Nonepk=Noneusername=''is_staff=Falseis_active=False......
  • 超链接<a>的属性及其链接方式
    1、语法:<ahref="超链接地址"target="在哪个页面打开">...<a/>举例: <ahref="https://www.baidu.com/"target="_blank">百度一下</a> -target属......
  • Winform中使用OpenFileDialog选择文件打开并获取文件路径
    场景在Windform中进行Excel导入时往往需要先将Excel文件打开并获取文件的路径,这时需要使用OpenFileDialog。OpenFileDialog显示一个标准对话框,提示用户打开文件。此类不能......
  • C# File.Exist 返回false 无法正确判断文件是否存在
    问题描述:首先澄清一下File.Exist并没有问题,为了让更多没有思路的朋友进来看明白什么原因导致这个问题的,我才会起这么一个标题现在我给大家讲一下为何会发生这个问题。在......
  • 6.7属性
    6.7属性 属性格式code属性 constantvalue属性Deprecated属性exceptions属性innerClass属性 LineNumerTable属性localvariableTable属性 sourceFile 属......