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>