[英]How to restrict file upload to JPG, PNG, and GIF in ASP.NET MVC 3
我正在以HTML格式使用簡單的輸入框<input type="file" />
,我想強制執行只能上傳JPG,PNG和GIF文件的操作。
我怎樣才能做到這一點?
您可以檢查此鏈接CodeProject:圖像上傳
$file = $("#yourFileuploadID");
var $filePath = $.trim($file.val());
if ($filePath == "") {
alert("Please browse a file to upload");
return;
}
var $ext = $filePath.split(".").pop().toLowerCase();
var $allow = new Array("gif", "png", "jpg", "jpeg");
if ($.inArray($ext, $allow) == -1) {
alert("Only image files are accepted, please browse a image file");
return;
}
PS:最好具有服務器端驗證,如果在客戶端禁用了javascript,它將很方便。 確保您同時檢查
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.