当前位置:编程学习 > asp >>

Asp.net FileUpload+Image制作头像效果

  在Web开发中会经常使用到个人信息注册,而个人信息中通常需要自己的头像或者照片。今天主要介绍一下使用FileUpload+img控件上传照片。

FileUpLoad控件使用介绍
FileUpLoad控件的PostedFile属性主要获取上传文件的一些基础信息。

.ContentLength
   获取上传文件的大小。返回值为int类型,单位为字节。

用途

1、判断上传文件的大小

    if (this.FileUpload1.PostedFile.ContentLength <= 4000000) //4M

        {

             Response.Write("<script>alert('" +FileUpload1.PostedFile.ContentLength + "')</script>");

       }

       else

       {

           Response.Write("<script>alert('太大了不能上传!')</script>");

       }

  其中FileUpload1是上传控件的ID,this.FileUpload1.PostedFile.ContentLength是上传文件的大小

2、修改ASP.NET上传的默认值

      ASP.NET的默认最大上传值是4M,通过修改web.config,可以实现上传大文件:

     <system.web>

<httpRuntime maxRequestLength="4096"//这里的4096就是4m,原先是默认的。你改一下这个,就可以了。

executionTimeout="3600"

/>

</system.web>

 

.ContentType
    获取上传文件的MIME内容类型。PostedFile.ContentType这个属性通常用来判断上传文件的MIME类型,我们通常以此来拒绝某些类型的上传,比如仅允许上传图像文件,或者指定固定图片的格式。

 


   在net,做上传文件判断文件格式的写法总结:


".*"="application/octet-stream"

".001"="application/x-001"

".301"="application/x-301"

".323"="text/h323"

".906"="application/x-906"

".907"="drawing/907"

".a11"="application/x-a11"

".acp"="audio/x-mei-aac"

".ai"="application/postscript"

".aif"="audio/aiff"

".aifc"="audio/aiff"

".aiff"="audio/aiff"

".anv"="application/x-anv"

".asa"="text/asa"

".asf"="video/x-ms-asf"

".asp"="text/asp"

".asx"="video/x-ms-asf"

".au"="audio/basic"

".avi"="video/avi"

".awf"="application/vnd.adobe.workflow"

".biz"="text/xml"

".bmp"="application/x-bmp"

".bot"="application/x-bot"

".c4t"="application/x-c4t"

".c90"="application/x-c90"

".cal"="application/x-cals"

".cat"="application/vnd.ms-pki.seccat"

".cdf"="application/x-netcdf"

".cdr"="application/x-cdr"

".cel"="application/x-cel"

".cer"="application/x-x509-ca-cert"

".cg4"="application/x-g4"

".cgm"="application/x-cgm"

".cit"="application/x-cit"

".class"="java/*"

".cml"="text/xml"

".cmp"="application/x-cmp"

".cmx"="application/x-cmx"

".cot"="application/x-cot"

".crl"="application/pkix-crl"

".crt"="application/x-x509-ca-cert"

".csi"="application/x-csi"

".css"="text/css"

".cut"="application/x-cut"

".dbf"="application/x-dbf"

".dbm"="application/x-dbm"

".dbx"="application/x-dbx"

".dcd"="text/xml"

".dcx"="application/x-dcx"

".der"="application/x-x509-ca-cert"

".dgn"="application/x-dgn"

".dib"="application/x-dib"

".dll"="application/x-msdownload"

".doc"="application/msword"

".dot"="application/msword"

".drw"="application/x-drw"

".dtd"="text/xml"

".dwf"="Model/vnd.dwf"

".dwf"="application/x-dwf"

".dwg"="application/x-dwg"

".dxb"="application/x-dxb"

".dxf"="application/x-dxf"

".edn"="application/vnd.adobe.edn"

".emf"="application/x-emf"

".eml"="message/rfc822"

".ent"="text/xml"

".epi"="application/x-epi"

".eps"="application/x-ps"

".eps"="application/postscript"

".etd"="application/x-ebx"

".exe"="application/x-msdownload"

".fax"="image/fax"

".fdf"="application/vnd.fdf"

".fif"="application/fractals"

".fo"="text/xml"

".frm"="application/x-frm"

".g4"="application/x-g4"

".gbr"="application/x-gbr"

".易做图"="application/x-易做图"

".gif"="image/gif"

".gl2"="application/x-gl2"

".gp4"="application/x-gp4"

".hgl"="application/x-hgl"

".hmr"="application/x-hmr"

".hpg"="application/x-hpgl"

".hpl"="application/x-hpl"

".hqx"="application/mac-binhex40"

".hrf"="application/x-hrf"

".hta"="application/hta"

".htc"="text/x-component"

".htm"="text/html"

".html"="text/html"

".htt"="text/webviewhtml"

".htx"="text/html"

".icb"="application/x-icb"

".ico"="image/x-icon"

".ico"="application/x-ico"

".iff"="application/x-iff"

".ig4"="application/x-g4"

".igs"="application/x-igs"

".iii"="application/x-iphone"

".img"="application/x-img"

".ins"="application/x-internet-signup"

".isp"="application/x-internet-signup"

".IVF"="video/x-ivf"

".java"="java/*"

".jfif"="image/jpeg"

".jpe"="image/jpeg"

".jpe"="application/x-jpe"

".jpeg"="image/jpeg"

".jpg"="application/x-jpg"

".js"="application/x-javascript"

".jsp"="text/html"

".la1"="audio/x-liquid-file"

".lar"="application/x-laplayer-reg"补充:Web开发 , ASP.Net ,

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,