導航:首頁 > 文件目錄 > jquery文件路徑上傳文件

jquery文件路徑上傳文件

發布時間:2022-09-16 23:49:30

Ⅰ 用jquery uploadify 上傳文件得到選擇的文件路徑!

fileObj.name得到的只是文件的名稱
你將IE的安全性調到最低,他得到的就是路徑,現在IE9對這個路徑進行了加密,所以得到的都是名字,就算的到路徑也是一個虛擬的路徑,最好將文件上傳,取文件上傳後的路徑進行操作。

javajs(可用jquery)如何獲取上傳文件原始路徑名

上傳文件時,我想獲取客戶端上傳文件的原始路徑。第一考慮,當然是使用js,例如網上可以找到的:
function getPath(obj) { if (obj) { if (window.navigator.userAgent.indexOf("MSIE") >= 1) { obj.select(); return document.selection.createRange().text; } else if (window.navigator.userAgent.indexOf("Firefox") >= 1) { if (obj.files) { return obj.files.item(0).getAsDataURL(); } return obj.value; } return obj.value; } } 但這樣的代碼在Ie下還是可行的,但在火狐下不兼容。所以又想通過servlet的第三方工具去做,例如FileUpload,本以為FileItem下的getName()方法能夠得到全路徑名,但結果仍然只得到文件名,很是杯具!求解決方法!?
引用<input type="file" name="file" />至於你說的,不明白你的意思關鍵問題是我要獲得這個路徑,並且傳遞到後台!用js會有兼容性問題,如果用FileUpload上傳,是否可以獲得呢?我是沒有得到的!!! 問題補充:zhanjia 寫道上傳文件一般用input標簽,type為file,瀏覽選擇文件後就是文件在本地的絕對路徑了
引用<input type="file" name="file" />至於你說的,不明白你的意思關鍵的問題是我要獲得這個本地路徑,並且傳到後台!用js可以得到,但存在兼容性問題!?如果用FileUpload呢?我暫時還沒有得到!!! 問題補充:zhanjia 寫道網上的一些解決方案:
一般都是上傳以後在資料庫中保存上傳後的文件路徑,本地路徑一般沒意義
除非像上面所說的文件上傳預覽,還有那麼點用處
我用來做數據介面的,我僅僅是把路徑傳給另一個系統,然後那個系統就可以從這個路徑取文件了。如果先上傳一次,再給對方,這樣不但影響上傳速度,而且會產生大量的垃圾文件。

Ⅲ jquery 多個 上傳文件教程

jquery 實現多個上傳文件教程:

首先創建解決方案,添加jquery的js和一些資源文件(如圖片和進度條顯示等):

jquery-1.3.2.min.js
jquery.uploadify.v2.1.0.js
jquery.uploadify.v2.1.0.min.js
swfobject.js
uploadify.css

1、頁面的基本代碼如下

這里用的是aspx頁面(html也是也可的)

頁面中引入的js和js函數如下:

<scriptsrc="js/jquery-1.3.2.min.js"type="text/javascript"></script>
<scriptsrc="js/jquery.uploadify.v2.1.0.js"type="text/javascript"></script>
<scriptsrc="js/jquery.uploadify.v2.1.0.min.js"type="text/javascript"></script>
<scriptsrc="js/swfobject.js"type="text/javascript"></script>
<linkhref="css/uploadify.css"rel="stylesheet"type="text/css"/>

</script>

js函數:

<scripttype="text/javascript">
$(document).ready(function(){

$("#uploadify").uploadify({
'uploader':'image/uploadify.swf',//uploadify.swf文件的相對路徑,該swf文件是一個帶有文字BROWSE的按鈕,點擊後淡出打開文件對話框
'script':'Handler1.ashx',//script:後台處理程序的相對路徑
'cancelImg':'image/cancel.png',
'buttenText':'請選擇文件',//瀏覽按鈕的文本,默認值:BROWSE。
'sizeLimit':999999999,//文件大小顯示
'floder':'Uploader',//上傳文件存放的目錄
'queueID':'fileQueue',//文件隊列的ID,該ID與存放文件隊列的div的ID一致
'queueSizeLimit':120,//上傳文件個數限制
'progressData':'speed',//上傳速度顯示
'auto':false,//是否自動上傳
'multi':true,//是否多文件上傳
//'onSelect':function(e,queueId,fileObj){
//alert("唯一標識:"+queueId+" "+
//"文件名:"+fileObj.name+" "+
//"文件大小:"+fileObj.size+" "+
//"創建時間:"+fileObj.creationDate+" "+
//"最後修改時間:"+fileObj.modificationDate+" "+
//"文件類型:"+fileObj.type);

//}
'onQueueComplete':function(queueData){
alert("文件上傳成功!");
return;
}

});
});

頁面中的控制項代碼:

<body>
<formid="form1"runat="server">
<divid="fileQueue">
</div>
<div>
<p>
<inputtype="file"name="uploadify"id="uploadify"/>
<inputid="Button1"type="button"value="上傳"onclick="javascript:$('#uploadify').uploadifyUpload()"/>
<inputid="Button2"type="button"value="取消"onclick="javascript:$('#uploadify').uploadifyClearQueue()"/>
</p>
</div>
</form>
</body>

函數主要參數:

$(document).ready(function(){
$('#fileInput1').fileUpload({
'uploader':'uploader.swf',//不多講了
'script':'/AjaxByJQuery/file.do',//處理Action
'cancelImg':'cancel.png',
'folder':'',//服務端默認保存路徑
'scriptData':{'methed':'uploadFile','arg1','value1'},
//向後台傳遞參數,methed,arg1為參數名,uploadFile,value1為對應的參數值,服務端通過request["arg1"]
'buttonText':'UpLoadFile',//按鈕顯示文字,不支持中文,解決方案見下
//'buttonImg':'圖片路徑',//通過設置背景圖片解決中文問題,就是把背景圖做成按鈕的樣子
'multi':'true',//多文件上傳開關
'fileExt':'*.xls;*.csv',//文件過濾器
'fileDesc':'.xls',//文件過濾器詳解見文檔
'onComplete':function(event,queueID,file,serverData,data){
//serverData為伺服器端返回的字元串值
alert(serverData);
}
});
});

後台一般處理文件:

usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.IO;
usingSystem.Net;
usingSystem.Web;
usingSystem.Web.Services;
namespacefupload
{
///<summary>
///Handler1的摘要說明
///</summary>
publicclassHandler1:IHttpHandler
{

publicvoidProcessRequest(HttpContextcontext)
{
context.Response.ContentType="text/plain";

HttpPostedFilefile=context.Request.Files["Filedata"];//對客戶端文件的訪問

stringuploadPath=HttpContext.Current.Server.MapPath(@context.Request["folder"])+"\";//伺服器端文件保存路徑

if(file!=null)
{
if(!Directory.Exists(uploadPath))
{
Directory.CreateDirectory(uploadPath);//創建服務端文件夾
}

file.SaveAs(uploadPath+file.FileName);//保存文件
context.Response.Write("上傳成功");
}

else
{
context.Response.Write("0");
}

}

publicboolIsReusable
{
get
{
returnfalse;
}
}
}
}

以上方式基本可以實現多文件的上傳,大文件大小是在控制在10M以下/。

Ⅳ java或js(可用jquery)如何獲取上傳文件原始路徑名

上傳文件時,我想獲取客戶端上傳文件的原始路徑。第一考慮,當然是使用js,例如網上可以找到的: function getPath(obj) { if (obj) { if (window.navigator.userAgent.indexOf("MSIE") >= 1) { obj.select(); return document.selection.createRange().text; } else if (window.navigator.userAgent.indexOf("Firefox") >= 1) { if (obj.files) { return obj.files.item(0).getAsDataURL(); } return obj.value; } return obj.value; } } 但這樣的代碼在Ie下還是可行的,但在火狐下不兼容。所以又想通過servlet的第三方工具去做,例如FileUpload,本以為FileItem下的getName()方法能夠得到全路徑名,但結果仍然只得到文件名,很是杯具!求解決方法!? 引用<input type="file" name="file" />至於你說的,不明白你的意思關鍵問題是我要獲得這個路徑,並且傳遞到後台!用js會有兼容性問題,如果用FileUpload上傳,是否可以獲得呢?我是沒有得到的!!! 問題補充:zhanjia 寫道上傳文件一般用input標簽,type為file,瀏覽選擇文件後就是文件在本地的絕對路徑了 引用<input type="file" name="file" />至於你說的,不明白你的意思關鍵的問題是我要獲得這個本地路徑,並且傳到後台!用js可以得到,但存在兼容性問題!?如果用FileUpload呢?我暫時還沒有得到!!! 問題補充:zhanjia 寫道網上的一些解決方案: 一般都是上傳以後在資料庫中保存上傳後的文件路徑,本地路徑一般沒意義 除非像上面所說的文件上傳預覽,還有那麼點用處 我用來做數據介面的,我僅僅是把路徑傳給另一個系統,然後那個系統就可以從這個路徑取文件了。如果先上傳一次,再給對方,這樣不但影響上傳速度,而且會產生大量的垃圾文件。

Ⅳ jQuery實現文件上傳。

/*jQuery實現文件上傳,參考例子如下:
packagecom.kinth.hddpt.file.action;

importjava.io.File;
importjava.io.FileNotFoundException;
importjava.io.FileOutputStream;
importjava.io.IOException;
importjava.io.InputStream;
importjava.io.OutputStream;
importjava.util.ArrayList;
importjava.util.Calendar;
importjava.util.Enumeration;
importjava.util.Hashtable;
importjava.util.List;

importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;

importnet.sf.json.JSONArray;

importorg.apache.commons.logging.Log;
importorg.apache.commons.logging.LogFactory;
importorg.apache.struts.action.ActionForm;
importorg.apache.struts.action.ActionForward;
importorg.apache.struts.action.ActionMapping;
importorg.apache.struts.upload.FormFile;
importorg.hibernate.criterion.MatchMode;
importorg.hibernate.criterion.Order;
importorg.hibernate.criterion.Restrictions;

importcom.gdcn.bpaf.common.base.search.MyCriteria;
importcom.gdcn.bpaf.common.base.search.MyCriteriaFactory;
importcom.gdcn.bpaf.common.base.service.BaseService;
importcom.gdcn.bpaf.common.helper.PagerList;
importcom.gdcn.bpaf.common.helper.WebHelper;
importcom.gdcn.bpaf.common.taglib.SplitPage;
importcom.gdcn.bpaf.security.model.LogonVO;
importcom.gdcn.components.appauth.common.helper.DictionaryHelper;
importcom.kinth.common.base.action.BaseAction;
importcom.kinth.hddpt.file.action.form.FileCatalogForm;
importcom.kinth.hddpt.file.model.FileCatalog;
importcom.kinth.hddpt.file.service.FileCatalogService;
importcom.kinth.hddpt.file.util.MyZTreeNode;

/**
*<p>
*description:「文件上傳的Struts層請求處理類」
*</p>
*@date:2013-1-14
*/
<FileCatalog>{
@SuppressWarnings("unused")
privatestaticLoglog=LogFactory.getLog(FileCatalogAction.class);//日誌記錄
;

//刪除記錄的同時刪除相應文件
publicActionForwardfileDelete(ActionMappingmapping,ActionFormform,
HttpServletRequestrequest,HttpServletResponseresponse)
throwsException{
String[]id=request.getParameterValues("resourceId");

if(id!=null&&id[0].contains(",")){
id=id[0].split(",");
}
String[]fileUrls=newString[id.length];
for(intj=0;j<id.length;j++){
fileUrls[j]=fileCatalogService.findObject(id[j]).getFileUrl();
if(!isEmpty(fileUrls[j])){
//如果該文件夾不存在則創建一個uptext文件夾
Filefileup=newFile(fileUrls[j]);
if(fileup.exists()||fileup!=null){
fileup.delete();
}
}

fileCatalogService.deleteObject(id[j]);
}
setAllActionInfos(request);
returnlist(mapping,form,request,response);
}


@Override
publicActionForwardsave(ActionMappingmapping,ActionFormform,
HttpServletRequestrequest,HttpServletResponseresponse)
throwsException{
Stringid=request.getParameter("resourceId");
BooleanfileFlag=Boolean.valueOf(request.getParameter("fileFlag"));

if(fileFlag!=null&&fileFlag==true){
returnsuper.save(mapping,form,request,response);
}else{
StringfileUrl=this.fileUpload(form,request,id,fileFlag);
response.setContentType("text/html");
response.setCharacterEncoding("GBK");
response.setHeader("Charset","GBK");
response.setHeader("Cache-Control","no-cache");
response.getWriter().write(fileUrl);
response.getWriter().flush();
}
returnnull;
}

@SuppressWarnings("unchecked")
publicStringfileUpload(ActionFormform,HttpServletRequestrequest,Stringid,BooleanfileFlag)throwsFileNotFoundException,IOException{

request.setCharacterEncoding("GBK");

StringbasePath=getServlet().getServletConfig().getServletContext().getRealPath("")+"/";
StringfilePath="uploads/";//獲取項目根路徑;

/*注釋部分對應jqueryuploaploadify插件的後台代碼,只是還存在編碼問題,默認為utf-8
StringsavePath=getServlet().getServletConfig().getServletContext().getRealPath("");//獲取項目根路徑
savePath=savePath+"\uploads\";
//讀取上傳來的文件信息
Hashtable<String,FormFile>fileHashtable=form.getMultipartRequestHandler().getFileElements();
Enumeration<String>enumeration=fileHashtable.keys();
enumeration.hasMoreElements();
Stringkey=(String)enumeration.nextElement();

FormFileformFile=(FormFile)fileHashtable.get(key);

Stringfilename=formFile.getFileName().trim();//文件名
filename=newEncodeChange().changeCode(filename);
Stringfiletype=filename.substring(filename.lastIndexOf(".")+1);//文件類型
savePath=savePath+filetype+"\";
System.out.println("path:"+savePath);
StringrealPath=savePath+filename;//真實文件路徑

//如果該文件夾不存在則創建一個文件夾
Filefileup=newFile(savePath);
if(!fileup.exists()||fileup==null){
fileup.mkdirs();
}
if(!filename.equals("")){
//在這里上傳文件
InputStreamis=formFile.getInputStream();
OutputStreamos=newFileOutputStream(realPath);
intbytesRead=0;
byte[]buffer=newbyte[8192];
while((bytesRead=is.read(buffer,0,8192))!=-1){
os.write(buffer,0,bytesRead);
}
os.close();
is.close();
//如果是修改操作,則刪除原來的文件
Stringid=request.getParameter("resourceId");
if(!isEmpty(id)){
FileCatalogfileCatalog=fileCatalogService.findObject(id);
StringfileUrl=fileCatalog.getFileUrl();
if(!isEmpty(fileUrl)){
Filefiledel=newFile(fileUrl);
if(filedel.exists()||filedel!=null){
filedel.delete();
}
}

request.setAttribute("entity",fileCatalog);
}

response.getWriter().print(realPath);//向頁面端返回結果信息
}*/

//讀取上傳來的文件信息
Hashtable<String,FormFile>fileHashtable=form.getMultipartRequestHandler().getFileElements();
Enumeration<String>enumeration=fileHashtable.keys();
enumeration.hasMoreElements();
Stringkey=(String)enumeration.nextElement();

FormFileformFile=(FormFile)fileHashtable.get(key);

Stringfilename=formFile.getFileName().trim();//文件名
Stringfiletype=filename.substring(filename.lastIndexOf(".")+1);//文件類型
IntegerfileSize=formFile.getFileSize();


filePath+=Calendar.getInstance().get(Calendar.YEAR)+"/"+filetype+"/";
StringrealPath=basePath+filePath+filename;//真實文件路徑

if(!filename.equals("")){
//如果是修改操作,則刪除原來的文件
if(!isEmpty(id)){
FileCatalogfileCatalog=fileCatalogService.findObject(id);
StringfileUrl=fileCatalog.getFileUrl();
if(!isEmpty(fileUrl)){
fileUrl=basePath+fileUrl;
Filefiledel=newFile(fileUrl);
if(filedel.exists()||filedel!=null){
filedel.delete();
}
}
request.setAttribute("entity",fileCatalog);
}
//如果該文件夾不存在則創建一個文件夾
Filefileup=newFile(basePath+filePath);
if(!fileup.exists()||fileup==null){
fileup.mkdirs();
}
//在這里上傳文件
InputStreamis=formFile.getInputStream();
OutputStreamos=newFileOutputStream(realPath);
intbytesRead=0;
byte[]buffer=newbyte[8192];
while((bytesRead=is.read(buffer,0,8192))!=-1){
os.write(buffer,0,bytesRead);
}
os.close();
is.close();
}
filePath+=filename;
Stringresult="{"fileName":""+filename+"","fileType":""+filetype+"","fileSize":"+fileSize+","fileUrl":""+filePath+""}";
returnresult;

}

(){
returnfileCatalogService;
}

(){
this.fileCatalogService=fileCatalogService;
}

}

Ⅵ jquery 知道文件路徑怎麼上傳

我的理解是你應該先通過圖片上傳介面把圖片上傳到伺服器上(上傳後的伺服器端的圖片地址,保存到<input type="hidden">里),然後再統一提交所有的表單項。

Ⅶ jquery1.8在IE11中獲取瀏覽器及版本號,及上傳文件時的文件絕對路徑和文件大小

獲取瀏覽復器版本:
$(document).ready(function(){
var bro=$.browser;
var binfo="";
if(bro.msie) {binfo="Microsoft Internet Explorer "+bro.version;}
if(bro.mozilla) {binfo="Mozilla Firefox "+bro.version;}
if(bro.safari) {binfo="Apple Safari "+bro.version;}
if(bro.opera) {binfo="Opera "+bro.version;}
alert(binfo);

})

上傳文件的話制,在客戶端的路徑可以用<input type="file" />中的值,伺服器端的路徑要看你服務端把它放到哪裡了,如果前台需要,可以在文件上傳完成後通過Ajax返回給客戶端

Ⅷ jquery或者js獲取上傳文件的路徑問題

我的理解是你應該先通過圖片上傳介面把圖片上傳到伺服器上(上傳後的伺服器端的圖片地址,保存到<input type="hidden">里),然後再統一提交所有的表單項。

Ⅸ jquery上傳文件是怎麼實現的

本篇文章是對Jquery中的LigerUI實現文件上傳的方法,進行了分析介紹,需要的朋友可以參考下
一、在Head中加入
<script src="../lib/js/ajaxfileupload.js" type="text/javascript"></script>
<script src="../lib/js/ligerui.expand.js" type="text/javascript"></script>
二、Html中的Div代碼

復制代碼 代碼如下:
<div id="AppendBill_Div" style="display:none;"> <%-- 上傳 - 單 --%>
<table style="height:100%;width:100%">
<tr style="height:40px">
<td style="width:20%">
圖標:
</td>
<td><input type="file" style="width:200px" id="fileupload" name="fileupload"/>
</td>
</tr>
</table>
</div>

三、Js中-寫的是關鍵部分,會LigerUI的朋友-你懂得
1、grid中添加項【存地址欄位】
{ display: "掃描件", name: "AppendBillPath", width: 120, type: "text", align: "left" }
2、Form可添加項【存地址和彈出選擇框】
{ name: "AppendBillPath1", type: "hidden" }, // --上傳-【5】--
{ display: "掃描件", name: "AppendBillPath", comboboxName: "AppendBillPath2", newline: true, labelWidth: 100, width: 150, space: 30, type: "select", options: {}} // --上傳-【6】--
$.ligerui.get("AppendBillPath2").set('onBeforeOpen', f_selectAppendBillPath_1) // 【掃描件】 // --上傳-【7】--
3、事件
// #region ======================================= 【上傳掃描件窗口】 // --上傳-【8】--
復制代碼 代碼如下:
var AppendBillPathDetail = null;
function f_selectAppendBillPath_1() {
var imageurl = $("#AppendBill").val();
var AppendBill_Id = $("#AppendBill").val(); // 單號
if (imageurl.length == 0) {
LG.showError("您沒有輸入單號,請輸入隨單號!");
return;
}
if (AppendBillPathDetail) {
AppendBillPathDetail.show();
}
else {
AppendBillPathDetail = $.ligerDialog.open({
target: $("#AppendBill_Div"), title: '添加圖標',
width: 360, height: 170, top: 170, left: 280, // 彈出窗口大小
buttons: [
{ text: '上傳', onclick: function () { AppendBillPath_save(); } },
{ text: '取消', onclick: function () { AppendBillPathDetail.hide(); } }
]
});
}
}
function AppendBillPath_save()
{
var imgurl = $("#fileupload").val();
// var filehelpcode = $("#filehelpcode").val();
var extend = imgurl.substring(imgurl.lastIndexOf("."), imgurl.length);
extend = extend.toLowerCase();
if (extend == ".jpg" || extend == ".jpeg" || extend == ".png" || extend == ".gif" || extend == ".bmp")
{
}
else
{
LG.showError("請上傳jpg,jpep,png,gif,bmp格式的圖片文件");
return;
}
var imageurl = $("#AppendBill").val(); // extend
alert(imageurl);
$.ajaxFileUpload({
url: "../handle/ImageUpload.aspx?imageurl=" + imageurl, // --上傳-【9】-- aspx文件
secureuri: false,
fileElementId: "fileupload", //Input file id
dataType: "text",
success: function (data, status)
{
// ----------------- // 保存路徑
// $("#AppendBillPath2").val(Data);

LG.tip(data);
f_reload();
},
error: function (data, status, e) {
LG.showError(data);
}
});
}
// #endregion

四、後台cs,寫一句關鍵的,可以返回參數,前台提示
string url = Server.MapPath("/Image/" + gfilename + filenameext); // 執行上傳操作

Ⅹ java或js(可用jquery)如何獲取上傳文件原始路徑名

上傳文件時,我想獲取客戶端上傳文件的原始路徑。第一考慮,當然是使用js,例如網上可以找到的:
function getPath(obj) { if (obj) { if (window.navigator.userAgent.indexOf("MSIE") >= 1) { obj.select(); return document.selection.createRange().text; } else if (window.navigator.userAgent.indexOf("Firefox") >= 1) { if (obj.files) { return obj.files.item(0).getAsDataURL(); } return obj.value; } return obj.value; } } 但這樣的代碼在Ie下還是可行的,但在火狐下不兼容。所以又想通過servlet的第三方工具去做,例如FileUpload,本以為FileItem下的getName()方法能夠得到全路徑名,但結果仍然只得到文件名,很是杯具!求解決方法!?
引用至於你說的,不明白你的意思關鍵問題是我要獲得這個路徑,並且傳遞到後台!用js會有兼容性問題,如果用FileUpload上傳,是否可以獲得呢?我是沒有得到的!!! 問題補充:zhanjia 寫道上傳文件一般用input標簽,type為file,瀏覽選擇文件後就是文件在本地的絕對路徑了
引用至於你說的,不明白你的意思關鍵的問題是我要獲得這個本地路徑,並且傳到後台!用js可以得到,但存在兼容性問題!?如果用FileUpload呢?我暫時還沒有得到!!! 問題補充:zhanjia 寫道網上的一些解決方案:
一般都是上傳以後在資料庫中保存上傳後的文件路徑,本地路徑一般沒意義
除非像上面所說的文件上傳預覽,還有那麼點用處
我用來做數據介面的,我僅僅是把路徑傳給另一個系統,然後那個系統就可以從這個路徑取文件了。

閱讀全文

與jquery文件路徑上傳文件相關的資料

熱點內容
手機設備添加列印文件格式 瀏覽:241
安卓的系統壁紙在哪個文件夾 瀏覽:331
iphone6s訂單截圖 瀏覽:874
machine怎麼編程 瀏覽:27
word插表格文件 瀏覽:264
保存的位置及配置文件的種類 瀏覽:812
開一家店必須看哪些數據 瀏覽:236
qq白板畫畫教程 瀏覽:625
3d壓縮文件的大小 瀏覽:325
macbookpro拖動文件 瀏覽:563
access資料庫創建報表 瀏覽:384
蘋果怎麼掃描文件發微信 瀏覽:205
cad導文件什麼格式 瀏覽:365
小米5s網路設置會怎麼樣 瀏覽:325
word2007空白處帶字體背景顏色 瀏覽:803
迷你編程第三章如何通關 瀏覽:342
win10系統怎麼卸載ie瀏覽器 瀏覽:587
uga字頭的字體在哪個文件 瀏覽:508
cad每次運行會產生log文件 瀏覽:158
單詞社交網路怎麼樣 瀏覽:406

友情鏈接