js 檢測上傳圖片類型與高寬(按星號調整)

來源:互聯網
上載者:User
關鍵字 網頁製作 Ajax JavaScript

js 檢測上傳圖片類型與高寬(按星號調整)

<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="提交" onclick="網頁特效: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;
  & nbsp; var height = img.height;
    img.onload = '';
    if (width > 480 || height > 320)
    {
      => 480*360
      var ratio1 = 320/width;
      var ratio 2 = 240/height;
      if (ratio1 > ratio2)
      {
         width = parseint(ratio2 * width);
        height = 240;
      }
      else
      {
         width = 320;
        height = parseint(ratio1 * height);
      }     
      alert('注意:圖片過大, 系統自動進行了一些調整');
 }
   
    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.lastin dexof('');
      form.title.value = isrc.substring(pos2+1,pos);
    }
    toi_update();
    delete img;
  };

on error
img.onerror = function () {
img.onerror = '';
alert('注意:您剛剛試圖上載的一個檔似乎不是合法圖片');
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>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.