导航:首页 > 文件目录 > 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文件路径上传文件相关的资料

热点内容
wps如何对比俩张数据表的异同点 浏览:716
哪种软件可以边语音边看视频 浏览:322
用友app怎么添加新品 浏览:359
中智e家微信 浏览:469
电影去除马赛克工具 浏览:519
关于犬抗战电影 浏览:733
照片如何转换w文件 浏览:713
如何把音频文件变小 浏览:637
哪个app可以制作表情包 浏览:215
xp默认文件夹图标ico 浏览:1000
kk93.TV T34.TV 浏览:216
有三个坏蛋三个男孩三个女孩的是啥电影 浏览:731
巧遇初恋电影免费观看 浏览:369
台湾红羊经典电影 浏览:400
免费剧情片在线播放网址 浏览:673
台湾红羊电影公司所有电影 浏览:628
泰国电影可怜的女孩 浏览:251
cad保存windows找不到文件 浏览:841
好看的快穿肉文小说 浏览:826
绩效评价程序 浏览:340

友情链接