当前位置:首页 » 文件管理 » extjs4多文件上传

extjs4多文件上传

发布时间: 2024-09-29 01:34:32

A. extjs ajax 可以上传文件吗

文件上传的Ajax,首先Ajax并不支持流的传输,只是在里面套了个iframe。

//ajax上传
Ext.get('btn').on('click',function(){
Ext.Ajax.request({
url:'Upload.php',
isUpload:true,
form:'upform',
success:function(){
Ext.Msg.alert('upfile','文件上传成功!');
}
});
});
<formid="upform">
请选择文件:<inputtype="file"name="imgFile"/>
<inputtype="button"id="btn"value="上传"/>
</form>
<?php
if(!isset($_FILES['imgFile'])){
echojson_encode(array("success"=>false,'msg'=>"NotgetImgfile"));
return;
}
$upfile=$_FILES['imgFile'];
$name=$upfile["name"];//上传文件的文件名
$type=$upfile["type"];//上传文件的类型
$size=$upfile["size"];//上传文件的大小
$tmp_name=$upfile["tmp_name"];//上传文件的临时存放路径
$error_cod=$upfile["error"];
if($error_cod>0){
echojson_encode(array("success"=>false,'msg'=>$error_cod));
}
$photo_tmp_file_name=//这里设置存放路径
move_uploaded_file($tmp_name,$photo_tmp_file_name);//存储文件
?>

B. 谁做过ExtJS上传下载文件的功能,求教

//附件上传表单
varwareFrom=Ext.create('Ext.form.Panel',{
items:[{
xtype:'filefield',
name:'upfile',
fieldLabel:'文件上传',
blankText:'请选择文件',
allowBlank:false
}]
});
//创建一个窗体
varwin=Ext.create('Ext.window.Window',{
title:'上传课件',
width:'auto',
height:'auto',
layout:'fit',
items:wareFrom,
buttonAlign:'center',
buttons:[{
minWidth:80,
text:'取消',
handler:function(){ win.hide(); }
},{
minWidth:80,
text:'上传',
handler:upLoad
}]
});
//显示窗体
win.show();
//点击上传按钮处理事件
functionupLoad(){
if(wareFrom.getForm().isValid()){
wareFrom.getForm().submit({
waitTitle:'请稍候',
waitMsg:'正在执行操作...',
url:'upload.php?upload=ok',
method:'POST',
success:function(form,action){
Ext.Msg.alert('提示',action.result.msg);
wareFrom.getForm().reset();
},
failure:function(form,action){
Ext.Msg.alert('提示',action.result.msg);
}
});
}
}

//后台不管你用的什么,流程一致,此以php为例,因为比较好写
<?php
if($_GET['upload']=='ok'){
//上传路径
$location='upload_file/';

//此处的name是上传窗体,upload控件的name
if(move_uploaded_file($_FILES['upfile']['tmp_name'],$location)){
echojson_encode(array('success'=>true,'msg'=>'上传成功'));
}else{
echojson_encode(array('success'=>false,'msg'=>'上传发生了错误'));
}
}
?>

//下载
<?php
//此处需前台传一个id过来
$id=$_GET['id'];
$sql="SELECT*FROM`ware`WHERE`id`='$id'";
$result=mysql_query($sql);
$row=mysql_fetch_row($result);

//此处的row是文件保存在数据库的路径
if(file_exists($row[0])){

//用stream读取该文件
$file=fopen($row[0],'r');
header('Content-Type:application/octet-stream');
header('Accept-Ranges:bytes');
header('Accept-Length:'.filesize($row[0]));

//此处的row1是文件名称
header('Content-Disposition:attachment;filename='.$row[1]);
echofread($file,filesize($row[0]));
fclose($file);
}
?>

//有什么地方不明白的话,欢迎继续追问

C. EXT html <input type='file' />上传文件 可以一次同时选多个文件吗

ftp上传工具。或者压缩文件后再上传。

D. 怎么将文件上传和表单提交分开处理

上传这样的功能本来就应该独立出来,为以后能够更好的扩展和组件重用做准备。至于你的这个问题也很容易处理,问题的关键不在于后台处理的程序如何安排,而在于页面的表现形式,因为程序本身既然独立出来了,你的ACTION也是独立出来的,那么就把页面里的上传功能独立出来。
举例来说:
在你的表单里添加一个上传按钮,点击后弹出一个漂浮的div图层,然后在这个图层里可以放置单个的文件浏览按钮,或者动态的增加多个需要上传的浏览按钮,都是很灵活的,然后把这个图层使用单独的form标签包围起来就可以了。
类似的功能像很多论坛程序都在使用,比较成熟的js组件也可以实现,比如ExtJs、jQuery等等,一般来说能够提供web editor功能的js组件对于上传都是类似的处理方式。

E. 我想用extjs实现上传和下载

给你上传代码,下载在服务端实现

重点是 xtype: 'filefield',
*************************************************************************
*上传框组件
*
************************************************************************
*/
Ext.define('Mocoolka.web.coreview.container.MKUploadForm', {
extend:'Ext.form.Panel',
frame: true,
autoScroll: true,
initComponent: function () {
var me = this;

me.title = getUIWithID("SystemUI.Buttons.Upload.Description");//'上传',

me.items = [
{
xtype: 'filefield',
emptyText: getUIWithID("SystemUI.MKUploadForm.SelectFile.Description"),//'选择一个文件',
name: 'filename',
buttonText: '...',
buttonConfig: {
iconCls: 'upload-icon'
}
},
];

me.buttons = [{
text: getUIWithID("SystemUI.Buttons.Upload.Description"),//'上传',
handler: function () {
var form = this.up('form').getForm();

var action = this.up('form').mkaction;
var myaction = "import";
if (action.get("Name") == "ImportAttachment")
myaction = "ImportAttachment";
var url = mkruntimer.getDataManager().getUrlPath(myaction, action);

if (form.isValid()) {
form.submit({
url: url,
waitMsg: getUIWithID("SystemUI.Buttons.Uploading.Description"),//'上传中...',
success: function (fp, o) {

var form1 = form.owner;
form1.mkcallout(form1.mkcalloutpara, action.result.children);
form1.up('window').close();

},
failure: function (form, action) {
mkerrorutil.processAjaxFailure(action.response);

}
});
}
}
}, {
text: getUIWithID("SystemUI.Buttons.Reset.Description"),//'重设',
handler: function () {
this.up('form').getForm().reset();
}
}, {
text: getUIWithID("SystemUI.Buttons.Cancel.Description"),//'取消',
handler: function () {
this.up('window').close();
}
},
{
text: getUIWithID("SystemUI.MKUploadForm.AddFile.Description"),//'增加一个文件',
handler: function () {
this.up('form').addFile();

}
}
]
me.callParent(arguments);

},
addFile: function () {
var me = this;
me.add({
xtype: 'filefield',
emptyText: getUIWithID("SystemUI.MKUploadForm.SelectFile.Description"),//'选择一个文件',
fieldLabel: getUIWithID(""),// '文件',
name: 'filename',
buttonText: '',
buttonConfig: {
iconCls: 'upload-icon'
}
});

},
//standardSubmit:false,

bodyPadding: '10 10 0',
flex:1,
defaults: {
anchor: '100%',

msgTarget: 'side',
labelWidth: 50
},
region: 'center',

});

F. ExtJs中的文件上传下载功能求教,100分

http://hi..com/%B1%F9%C3%CE%CE%DE%BA%DB/blog/item/3b19542954c90ff799250a29.html

前台EXT(假设上传文件为2个):主要就是个formPanel,items中写为:

{
xtype : 'textfield',
fieldLabel : '上传文件1',
name : 'file',
inputType : 'file'
}, {
xtype : 'textfield',
fieldLabel : '上传文件2',
name : 'file',
inputType : 'file'
}

其他地方不详细诉说了,不明白看EXT表单提交去,别忘记fileUpload : true就可以了

注意:因为是用struts2处理,name都是一样的file

struts2后台:

private List<File> file;对应前面的name
// 使用列表保存多个上传文件的文件名
private List<String> fileFileName;
// 使用列表保存多个上传文件的MIME类型
private List<String> fileContentType;
// 保存上传文件的目录,相对于Web应用程序的根路径,在struts.xml文件中配置
private String uploadDir;

get/set方法略

public void fileUpLoad() {
String newFileName = null;
BufferedOutputStream bos = null;
BufferedInputStream bis = null;
String reInfo="";//上传成功返回的东西
for (int i = 0; i < file.size(); i++) {
long now = new Date().getTime();
int index = fileFileName.get(i).lastIndexOf('.');
String path = ServletActionContext.getServletContext().getRealPath(
uploadDir);
File dir = new File(path);
if (!dir.exists())
dir.mkdir();//创建个文件夹
if (index != -1)
newFileName = fileFileName.get(i).substring(0, index) + "-"
+ now + fileFileName.get(i).substring(index);//生成新文件名
else
newFileName = fileFileName.get(i) + "-" + now;
reInfo+=newFileName+"@";
bos = null;
bis = null;
try {
FileInputStream fis = new FileInputStream(file.get(i)); // /////////
bis = new BufferedInputStream(fis);
FileOutputStream fos = new FileOutputStream(new File(dir,
newFileName));
bos = new BufferedOutputStream(fos);
byte[] buf = new byte[4096];
int len = -1;
while ((len = bis.read(buf)) != -1) {
bos.write(buf, 0, len);
}
} catch (Exception e) {
/////错误返回
try {
HttpServletResponse response = ApplicationWebRequestContext
.getWebApplicationContext().getResponse();
String msg = "{success:false,errors:{name:'上传错误'}}";
response.getWriter().write(msg);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
////////
} finally {
////////////////////////善后
try {
if (null != bis)
bis.close();
} catch (IOException e) {
e.printStackTrace();
}

try {
if (null != bos)
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
////////////////////////////////
}

//最后若没错误返回就这里返回了
try {
HttpServletResponse response = ApplicationWebRequestContext
.getWebApplicationContext().getResponse();
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html");
String msg = "{success:true,msg:'"+reInfo+"'}";
response.getWriter().write(msg);

} catch (Exception e) {
e.printStackTrace();
}
}
改方法参考了孙鑫的strut2深入详解,自己修改而成

注意上面2个黑体,尤其是第2行,不加的话浏览器会很悲剧的再你上传陈宫以后的返回前后加上<pre>,于是ext表单获得返回失败,这就是为什么有些人用其他EXT上传组件时候上传成功一直卡成进度条那

G. extjs怎么判断上传文件名的名称格式大小,不是后缀是文件名称

ExtJs能不能不知道(貌似不可以),但是可以用别的方式达到。给你提供个思路:比袜握如你限制仅能上传txt,pdf,xml,doc格式的文件,上传
时,先获取上传的文件名,截基岁取文件的后缀名(这个很简单,用split功能就可以了,以
.(点)作为分隔符),然后跟允许的上传格式字符对比,如果不同,则不允许上传,相同则允许(其实搏好睁用正则表达式也是可以的)。比如:
var a="filename.pdf"(文件名自己去获取)
var b=a.split(".")(截取之后是个数组["filename","pdf"])
b[1]就是后缀名pdf
这样再对比:if(
b[1]
.toLowerCase()==‘pdf’)
alert("ok");

H. Extjs4.2上传文本框只读和赋值

使用setReadOnly(true)方法改为只读

I. ExtJs可以限制上传文件的格式吗

ExtJs能不能不知道(貌似不可以),但是可以用别的方式达到。给你提供个思路:比如你限制仅能上传txt,pdf,xml,doc格式的文件,上传时,先获取上传的文件名,截取文件的后缀名(这个很简单,用split功能就可以了,以 .(点)作为分隔符),然后跟允许的上传格式字符对比,如果不同,则不允许上传,相同则允许(其实用正则表达式也是可以的)。比如:
var a="filename.pdf"(文件名自己去获取)
var b=a.split(".")(截取之后是个数组["filename","pdf"])
b[1]就是后缀名pdf
这样再对比:if(
b[1]
.toLowerCase()==‘pdf’)
alert("ok");

热点内容
protues用什么编译器 发布:2024-09-29 04:04:12 浏览:420
bab编程 发布:2024-09-29 03:48:58 浏览:932
魔兽世界服务器新是什么意思 发布:2024-09-29 03:43:48 浏览:389
吉利博越自动挡哪个配置最好 发布:2024-09-29 03:43:26 浏览:760
服务器出现故障码怎么解决 发布:2024-09-29 03:40:50 浏览:181
公费访问学者 发布:2024-09-29 03:33:12 浏览:309
云主机源码 发布:2024-09-29 03:18:28 浏览:663
cspython 发布:2024-09-29 02:58:07 浏览:738
下载加密日记软件 发布:2024-09-29 02:58:07 浏览:800
晴天服务器我的世界 发布:2024-09-29 02:57:58 浏览:448