JS detection upload picture type and width (scaled)

Source: Internet
Author: User
Keywords Web page production Ajax javascript
Tags ajax data document function javascript name type upload

JS detection upload picture type and width (scaled)

<form action= "" method= "Post" enctype= "Multipart/form-data" name= "Dform" >
<label for= "IFile" ></label>
<input type= "File" Name= "IFile" id= "IFile" >
<input type= "Submit" name= "button" id= "button" value= "Submit" onclick= "Web Effects: toi_upimg ();" >
</form>
<script>
function toi_upimg ()
{
var form = Document.dform;
var isrc = Form.ifile.value;
var pos = Isrc.lastindexof ('. ');
var img = new Image ();

 //On load
  img.onload = function () {
    var width = img.width;
     var height = img.height;
    img.onload = ';
    if (Width > | | height >)
    {
      => 480*360
      var ratio1 = 320/width;
      var Ratio2 = 240/height;
      if (Ratio1 > Ratio2)
      {
         width = parseint (Ratio2 * width);
        height = 240;
     }
      Else
      {
         width = 320;
        height = parseint (ratio1 * height);
     }     
      alert (' Note: The picture is too large, the system has made some adjustments automatically ');
 
   
    toi_img.src = img.src;
    toi_img.width = width;
    toi_img.height = height;
  Form.picwidth.value = width;
  Form.picheight.value = height;
  Form.mserver.value = "no";
    form.xpost.value = ' 0 ';
    form.ypost.value = ' 0 ';
    form.xposy.value = ' 0 ';
    form.yposy.value = ' 0 ';
    form.xposa.value = ' 0 ';
    form.yposa.value = ' 0 ';
 if (Form.title.value = = ")
    {
      var pos2 = Isrc.lastindexof (");
      form.title.value = isrc.substring (Pos2+1,pos);
   }
    toi_update ();
    delete img;
 };

On Error
Img.onerror = function () {
Img.onerror = ';
Alert (' Note: A file you just tried to upload does not appear to be a legitimate picture ');
Delete img;
};

Store the source address
if (Navigator.appversion.indexof (' Msie 7 ') >= 0)
{
document.getElementById ("Filterimage"). Filters.item ("Dximagetransform.microsoft.alphaimageloader"). src = isrc;
IMG.SRC = document.getElementById ("Filterimage"). Filters.item ("Dximagetransform.microsoft.alphaimageloader"). src ;
}
Else
{
IMG.SRC = ISRC;
}
}
</script>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.