//置於<Head>之間
<script language="JavaScript">
<!--
//檢查上傳物件 checkFileUpload(表單名稱,檔案類型,是否需要上傳,檔案大小,圖片最小寬度,圖片最小高度,圖片最大寬度,圖片最大高度,儲存寬度的表單名稱,儲存高度的表單名稱)
function checkFileUpload(form,extensions,requireUpload,sizeLimit,minWidth,minHeight,maxWidth,maxHeight,saveWidth,saveHeight) {
document.MM_returnValue = true;
if (extensions != '') var re = new RegExp("\.(" + extensions.replace(/,/gi,"|") + ")$","i");
for (var i = 0; i<form.elements.length; i++) {
field = form.elements[i];
if (field.type.toUpperCase() != 'FILE') continue;
if (field.value == '') {
if (requireUpload) {alert('請選取上傳的檔案!');document.MM_returnValue = false;field.focus();break;}
} else {
if(extensions != '' && !re.test(field.value)) {
alert('這個檔案不符合上傳的類型!\n只有以下的類型才允許上傳: ' + extensions + '。\n請依規定選取新的上傳檔案。');
document.MM_returnValue = false;field.focus();break;
}
document.PU_uploadForm = form;
re = new RegExp(".(gif|jpg|png|bmp|jpeg)$","i");
if(re.test(field.value) && (sizeLimit != '' || minWidth != '' || minHeight != '' || maxWidth != '' || maxHeight != '' || saveWidth != '' || saveHeight != '')) {
setTimeout('if (document.MM_returnValue) document.PU_uploadForm.submit()',500);
checkImageDimensions(field.value,sizeLimit,minWidth,minHeight,maxWidth,maxHeight,saveWidth,saveHeight);
} } }
}
//-->
</script>
//置於<body>裡面
onSubmit="checkFileUpload(this,'GIF,JPG,JPEG,PNG,BMP',true,'','','','','','','');return document.MM_returnValue"