投放本站广告请联系:
extjscn#126.com
上传表单(Upload Forms)[PHP版]
ExtJs的文件上传功能官方的例子中并没有,但做网站的都知道,这个功能在十个系统中九个可能都需要这样的功能。废话少说,下面一起来分享一下ExtJs上传文件功能。
为了更方便asp.net的会员,于是写了另一篇上传表单(Upload Forms)[ASP.NET版]的。请点击这里查看.
演示(demo)地址在文章最后.
效果图1(上传前):

效果图2(上传后):

该程序包括三个文件,一个文件件。如下图

源代码:
upload.html
<html>
<head>
<title>Uploading</title>
<link rel="stylesheet" type="text/css" href="../../resources/css/ext-all.css"/>
<!-- GC -->
<!-- LIBS -->
<script type="text/javascript" src="../../adapter/ext/ext-base.js"></script>
<!-- ENDLIBS -->
<script type="text/javascript" src="../../ext-all.js"></script>
<script type="text/javascript" src="upload.js"></script>
<link rel="stylesheet" type="text/css" href="forms.css"/>
<!-- Common Styles for the examples -->
<link rel="stylesheet" type="text/css" href="../examples.css"/>
</head>
<body>
<script type="text/javascript" src="../examples.js"></script>
<!-- EXAMPLES -->
<h1>Upload with Forms</h1>
<p>The js is not minified so it is readable. See
<a href="upload.js">upload.js</a>.</p>
<p> </p>
<p><a href="javascript:window.location.reload();">reload</a></p>
</body>
</html>
upload.js
Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'side';
Ext.onReady(function() {
var form = new Ext.form.FormPanel({
baseCls: 'x-plain',
labelWidth: 80,
url:'upload.php',
fileUpload:true,
defaultType: 'textfield',
items: [{
xtype: 'textfield',
fieldLabel: 'File Name',
name: 'userfile',
inputType: 'file',
allowBlank: false,
blankText: 'File can\'t not empty.',
anchor: '90%' // anchor width by percentage
}]
});
var win = new Ext.Window({
title: 'Upload file',
width: 400,
height:200,
minWidth: 300,
minHeight: 100,
layout: 'fit',
plain:true,
bodyStyle:'padding:5px;',
buttonAlign:'center',
items: form,
buttons: [{
text: 'Upload',
handler: function() {
if(form.form.isValid()){
Ext.MessageBox.show({
title: 'Please wait',
msg: 'Uploading...',
progressText: '',
width:300,
progress:true,
closable:false,
animEl: 'loding'
});
form.getForm().submit({
success: function(form, action){
Ext.Msg.alert('Message from extjs.org.cn',action.result.msg);
win.hide();
},
failure: function(){
Ext.Msg.alert('Error', 'File upload failure.');
}
})
}
}
},{
text: 'Close',
handler:function(){win.hide();}
}]
});
win.show();
});
upload.php
<?php
//上传文件全称
$uploadfile = "upload_files/".basename($_FILES['userfile']['name']);
$message = "";
if (@move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
$message = "File was successfully uploaded.";
}
else
{
$message = "Possible file upload attack!";
}
print "{success:true,msg:'".$message."'}";
?>
还需要在当前目录创建一个文件夹upload_files,并将该文件夹设置为777(everyone 可读写).
演示地址:http://extjs.org.cn/extjs/examples/form/upload.html
(版权声明:本篇文章版权属于extjs.org.cn所有,可以在互联网上进行转载,转载必须保留作者版权声明及链接;也可以文章用于出版、发行或其它商业用途,仅仅需要保留作者版权声明及链接。)
- 关键字:
- 要发表评论,请先登录


评论
评论:
此网站的设计是太棒了。我怎么能成为最佳网页设计师!并希望我的概念,明确 testking 000-061。和以及其他重要的一个 testking JN0-311 这些考试/证书考虑在IT领域的土地的标志。我希望会有一个单独的部分为 testking 70-293 以及与此相关的其他条款。
php的看不懂,能不能给个.net例子
上面的php的代码看不懂,能不能给个.net例子,谢谢。
已加上 ASP.NET 的例子
详细请点击 上传表单(Upload Forms)[ASP.NET版]
尽快加上asp.net例子
我将会在下个星期三之前更新一个 asp.net(C#) 版本的上传表单到网站上来。
敬请期待!
目录下没有文件检测上传程序的方法
1、去掉upload.php函数前的@符号
<?php //上传文件全称 $uploadfile = "upload_files/".basename($_FILES['userfile']['name']); $message = ""; if (@move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { $message = "File was successfully uploaded."; } else { $message = "Possible file upload attack!"; } print "{success:true,msg:'".$message."'}"; ?>2、写一个普通的HTML先测试一下你的上传程序有无问题。
请教:报“result.msg”为空或不是对象错误!
我将
Ext.Msg.alert('Message from extjs.org.cn',action.result.msg);
改为
Ext.Msg.alert('Success','File upload success.');
上传文件后,提示上传成功,但upload_files文件夹下什么都没有,不知道这是为什么。
同时我用的是ext-2.1
没有
<script type="text/javascript" src="../examples.js"></script>
但找到了这个,不知道是不是
<script type="text/javascript" src="../samples.js"></script>