Extjs php fileupload

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>&nbsp;</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."'}";
?>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值