當前位置:首頁 » 文件管理 » 前端上傳控制項

前端上傳控制項

發布時間: 2023-06-16 11:34:26

① Bootstrap-fileinput上傳控制項 前端JS怎麼獲取伺服器端執行後的返回值,求解

$("#file1").on("fileuploaded", function (event, data, previewId, index) {
va url = data.response.Result;
});

② 前端上傳文件的幾種方法

1.表單上傳

最傳統的圖片上傳方式是form表單上傳,使用form表單的input[type=」file」]控制項,打開系統的文件選擇對話框,從而達到選擇文件並上傳的目的。

form表單上傳

表單上傳需要注意以下幾點:

(1).提供form表單,method必須是post。

(2).form表單的enctype必須是multipart/form-data。

javascript學習交流群:453833554

enctype 屬性規定在發送到伺服器之前應該如何對表單數據進行編碼。默認地,表單數據會編碼為 "application/x-www-form-urlencoded"。就是說,在發送到伺服器之前,所有字元都會進行編碼。HTML表單如何打包數據文件是由enctype這個屬性決定的。enctype有以下幾種取值:

application/x-www-form-urlencoded:在發送前編碼所有字元(默認)(空格被編碼為』+』,特殊字元被編碼為ASCII十六進制字元)。

multipart/form-data:不對字元編碼。在使用包含文件上傳控制項的表單時,必須使用該值。

text/plain:空格轉換為 「+」 加號,但不對特殊字元編碼。

默認enctype=application/x-www-form-urlencoded,所以表單的內容會按URL規則編碼,然後根據表單的提交方法:

method=』get』 編碼後的表單內容附加在請求連接後,

method=』post』 編碼後的表單內容作為post請求的正文內容。

③ web前端上傳圖片的幾種方法

下面給你介紹3種web前端上傳圖片的方法:

1.表單上傳

最傳統的圖片上傳方式是form表單上傳,使用form表單的input[type=」file」]控制項,打開系統的文件選擇對話框,從而達到選擇文件並上傳的目的。

ajax無刷新上傳

Ajax無刷新上傳的方式,本質上與表單上傳無異,只是把表單里的內容提出來採用ajax提交,並且由前端決定請求結果回傳後的展示結果。

3.各類插件上傳

當上傳的需求要求可預覽、顯示上傳進度、中斷上傳過程、大文件分片上傳等等,這時傳統的表單上傳很難實現這些功能,我們可以藉助現有插件完成。

如網路上傳插件Web Uploader、jQuery圖片預覽插件imgPreview 、拖拽上傳與圖像預覽插件Dropzone.js等等,大家可根據項目實際需求選擇適合的插件。

④ ext js 瀏覽控制項(上傳圖片功能)

用js或者提交後後台檢測fileExt。
js:
<script language="JavaScript" type="text/JavaScript">
var img=null;
function checkPic(Form1){
var location=Form1.pic.value;
if(location==""){
alert("友情提示:\n\n請先選擇圖片文件,然後再點擊「上傳照片」按鈕。");
window.location.href=window.location.href;
return false;
}
var point = location.lastIndexOf(".");
var type = location.substr(point);
if(type==".jpg"||type==".gif"||type==".png"||type==".JPG"||type==".GIF"||type==".PNG"){
img=document.createElement("img");
img.style.position="absolute";
img.style.visibility="hidden";
document.body.insertAdjacentElement("beforeend",img);
img.src=location;
//if(img.fileSize>35540)
if(img.fileSize>102400) {
alert("友情提示:\n\n您上傳的圖片尺寸超過了網站的限定,請不要大於102400位元組,寬度小於450px。\n\n您目前上傳的圖片寬度:"+img.offsetWidth+"px,高度:"+img.offsetHeight+"px,圖片大小:"+img.fileSize+"位元組。\n\n請調整到規定大小再上傳!謝謝合作!");
window.location.href=window.location.href;
return false;
}else
return true;
}
else{
alert("友情提示:您要上傳的圖片格式不對!\n\n只能輸入jpg、png或者gif格式的圖片,\n\n請重新選擇圖片!謝謝合作!");
window.location.href=window.location.href;
return false;
}
return true;

}
function changesrc(){
yourpic.src=Form1.pic.value;
}
</script>

後台:
<%
set upload=new upload_file
if upload.form("act")="uploadfile" then
filepath=trim(upload.form("filepath"))
filelx=trim(upload.form("filelx"))

i=0
for each formName in upload.File
set file=upload.File(formName)

fileExt=lcase(file.FileExt) '得到的文件擴展名不含有.
if file.filesize<100 then
response.write "<span style=""font-family: 宋體; font-size: 9pt"">請先選擇你要上傳的文件![ <a href=# onclick=history.go(-1)>重新上傳</a> ]</span>"
response.end
end if
if (filelx<>"swf") and (filelx<>"jpg") then
'response.write "<span style=""font-family: 宋體; font-size: 9pt"">該文件類型不能上傳![ <a href=# onclick=history.go(-1)>重新上傳</a> ]</span>"
'response.end
response.write "<script language='javascript'>" & VbCRlf
response.write "alert('友情提示:\n\n您上傳出錯啦!該文件類型不能上傳!\n\n請重新選擇文件再上傳,請點擊「確定」重新輸入!');" & VbCrlf
response.write "history.go(-1);" & vbCrlf
response.write "</script>" & VbCRLF
response.end
end if
if filelx="swf" then
if fileext<>"swf" then
'response.write "<span style=""font-family: 宋體; font-size: 9pt"">只能上傳swf格式的Flash文件![ <a href=# onclick=history.go(-1)>重新上傳</a> ]</span>"
'response.end
response.write "<script language='javascript'>" & VbCRlf
response.write "alert('友情提示:\n\n您上傳出錯啦!只能上傳swf格式的Flash文件!\n\n請重新選擇文件再上傳,請點擊「確定」重新輸入!');" & VbCrlf
response.write "history.go(-1);" & vbCrlf
response.write "</script>" & VbCRLF
response.end
end if
end if
if filelx="jpg" then
if fileext<>"gif" and fileext<>"jpg" and fileext<>"png" then
'response.write "<span style=""font-family: 宋體; font-size: 9pt"">只能上傳jpg或gif格式的圖片![ <a href=# onclick=history.go(-1)>重新上傳</a> ]</span>"
'response.end
response.write "<script language='javascript'>" & VbCRlf
response.write "alert('友情提示:\n\n您上傳出錯啦!只能上傳jpg、png或gif格式的圖片!\n\n請重新選擇文件再上傳,請點擊「確定」重新輸入!');" & VbCrlf
response.write "history.go(-1);" & vbCrlf
response.write "</script>" & VbCRLF
response.end
end if
end if
if filelx="swf" then
if file.filesize>(3000*1024) then
'response.write "<span style=""font-family: 宋體; font-size: 9pt"">最大隻能上傳 3M 的Flash文件![ <a href=# onclick=history.go(-1)>重新上傳</a> ]</span>"
'response.end
response.write "<script language='javascript'>" & VbCRlf
response.write "alert('友情提示:\n\n您上傳出錯啦!最大隻能上傳 300k 的Flash文件!\n\n請重新選擇文件再上傳,請點擊「確定」重新輸入!');" & VbCrlf
response.write "history.go(-1);" & vbCrlf
response.write "</script>" & VbCRLF
response.end
end if
end if
if filelx="jpg" then
if file.filesize>(200*724) then
'response.write "<span style=""font-family: 宋體; font-size: 9pt"">最大隻能上傳 1000K 的圖片文件![ <a href=# onclick=history.go(-1)>重新上傳</a> ]</span>"
'response.end
response.write "<script language='javascript'>" & VbCRlf
response.write "alert('友情提示:\n\n您上傳的圖片尺寸超過了網站的限定,最大隻能上傳 600K 的圖片文件!\n\n請將圖片調整到寬度為:450px,小於規定大小再上傳!\n\n請點擊「確定」重新輸入!');" & VbCrlf
response.write "history.go(-1);" & vbCrlf
response.write "</script>" & VbCRLF
response.end
end if
end if
%>
要注意與上傳控制項一起配合好才行的。 有問題找偶。

⑤ 怎樣用JS控制文件上傳時FILE控制項內默認的文件類型

有兩種方式,
1、用fileupload控制項在後台判斷
FileUpload1.FileContent.Length判斷大小,
System.IO.Path.GetExtension(FileUpload1.FileName)獲取文件後綴
2、用jquery上傳控制項,可以直接判斷類型和大小
另外js也可以在前台判斷文件類型,但不能獲取文件大小,需要引用插件

熱點內容
黑鯊手機哪裡看安卓版本 發布:2025-02-06 01:36:04 瀏覽:802
如何配置2檸檬酸 發布:2025-02-06 00:57:26 瀏覽:435
積木源碼 發布:2025-02-06 00:55:26 瀏覽:546
變分的運演算法則 發布:2025-02-06 00:55:21 瀏覽:776
x2哪個配置性價比高 發布:2025-02-06 00:40:12 瀏覽:110
豬哥亮訪問張菲 發布:2025-02-06 00:37:52 瀏覽:571
期貨賬戶怎麼改密碼 發布:2025-02-06 00:32:35 瀏覽:280
qq自動上傳群文件 發布:2025-02-06 00:26:25 瀏覽:112
安卓照片放在什麼地方 發布:2025-02-06 00:26:24 瀏覽:989
linux系統鏡像iso 發布:2025-02-06 00:15:39 瀏覽:189