Extjs文件上传

head>
03.     <title>Uploading</title>
04.     <link rel="stylesheet" type="text/css" href="../../resources/css/ext-all.css"/>
05.   
06.     <!-- GC -->
07.     <!-- LIBS -->
08.     <script type="text/javascript" src="../../adapter/ext/ext-base.js"></script>
09.     <!-- ENDLIBS -->
10.   
11.     <script type="text/javascript" src="../../ext-all.js"></script>
12.   
13.     <script type="text/javascript" src="upload.js"></script>
14.     <link rel="stylesheet" type="text/css" href="forms.css"/>
15.   
16.     <!-- Common Styles for the examples -->
17.     <link rel="stylesheet" type="text/css" href="../examples.css"/>
18. </head>
19. <body>
20. <script type="text/javascript" src="../examples.js"></script>
21. <!-- EXAMPLES -->
22. <h1>Upload with Forms</h1>
23.   
24. <p>The js is not minified so it is readable. See 
25. <a href="upload.js">upload.js</a>.</p>
26. <p> </p>
27. <p><a href="javascript:window.location.reload();">reload</a></p>
28. </body>
29. </html>

upload.js

01. Ext.QuickTips.init();
02. Ext.form.Field.prototype.msgTarget = 'side'
03. Ext.onReady(function() {
04.   var form = new Ext.form.FormPanel({
05.     baseCls: 'x-plain',
06.     labelWidth: 80,
07.     url:'upload.php',
08.     fileUpload:true,
09.     defaultType: 'textfield',
10.   
11.     items: [{
12.       xtype: 'textfield',
13.       fieldLabel: 'File Name',
14.       name: 'userfile',
15.       inputType: 'file',
16.       allowBlank: false,
17.       blankText: 'File can\'t not empty.',
18.       anchor: '90%'  // anchor width by percentage
19.     }]
20.   });
21.   
22.   var win = new Ext.Window({
23.     title: 'Upload file',
24.     width: 400,
25.     height:200,
26.     minWidth: 300,
27.     minHeight: 100,
28.     layout: 'fit',
29.     plain:true,
30.     bodyStyle:'padding:5px;',
31.     buttonAlign:'center',
32.     items: form,
33.   
34.     buttons: [{
35.       text: 'Upload',
36.       handler: function() {
37.         if(form.form.isValid()){
38.           Ext.MessageBox.show({
39.                title: 'Please wait',
40.                msg: 'Uploading...',
41.                progressText: '',
42.                width:300,
43.                progress:true,
44.                closable:false,
45.                animEl: 'loding'
46.              });
47.           form.getForm().submit({    
48.             success: function(form, action){
49.                Ext.Msg.alert('Message from extjs.org.cn',action.result.msg);
50.                win.hide();  
51.             },    
52.              failure: function(){    
53.               Ext.Msg.alert('Error', 'File upload failure.');    
54.              }
55.           })           
56.         }
57.        }
58.     },{
59.       text: 'Close',
60.       handler:function(){win.hide();}
61.     }]
62.   });
63.   win.show();
64. });

upload.php

01. <?php
02. //上传文件全称
03. $uploadfile = "upload_files/".basename($_FILES['userfile']['name']);
04.   
05. $message = "";
06. if (@move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
07.     $message = "File was successfully uploaded.";
08.
09. else 
10. {
11.     $message = "Possible file upload attack!";
12. }
13.   
14. print "{success:true,msg:'".$message."'}";
15. ?>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值