Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用Extjs上传文件_Javascript_Extjs - Fatal编程技术网

Javascript 使用Extjs上传文件

Javascript 使用Extjs上传文件,javascript,extjs,Javascript,Extjs,嗨,我已经写了一个上传文件和插入到数据库的代码,所以我需要得到上传文件的字节 这是我的代码: { xtype:'filefield', id:'AttachData', 名称:'文件路径', emptyText:“上载文档…”, 边距:“15 0 0 0”, buttonText:'浏览', msgTarget:'侧面', allowBlank:false, 主播:100%, 禁用:false }, { xtype:'按钮', 文本:“上传”, 边距:“15 0 10”, 处理程序:函数(){

嗨,我已经写了一个上传文件和插入到数据库的代码,所以我需要得到上传文件的字节

这是我的代码:

{
xtype:'filefield',
id:'AttachData',
名称:'文件路径',
emptyText:“上载文档…”,
边距:“15 0 0 0”,
buttonText:'浏览',
msgTarget:'侧面',
allowBlank:false,
主播:100%,
禁用:false
}, {
xtype:'按钮',
文本:“上传”,
边距:“15 0 10”,
处理程序:函数(){
var form=this.up('form').getForm();
if(form.isValid()){
提交表格({
url:“../UploadAttachment.aspx”,
标题:{
“内容类型”:“应用程序/json;字符集=utf-8”
},
waitMsg:'正在上载您的文件…',
成功:功能(响应、行动){
isUploded=true;
msg('Success','Processed file'+action.result.file+'(在服务器上));
},
故障:功能(响应、动作){
控制台日志(操作);
Ext.Msg.alert('Failed',response.message?action.result.message:'No response');
}
});
}
}

},
当您的请求将转到“UploadAttachment.aspx”页面时,只需在那里创建一个函数来获取上传的文件详细信息,并用URL指定函数名。因此,该函数很容易调用到服务器端或在aspx页面中

您可以使用下面的代码获得上传文件的完整详细信息

HttpPostedFile uploadFile = Context.Request.Files["file-path"];
现在您可以在uploadFile变量中获得有关上载文件的所有信息

Default.aspx(编码)


此代码是否在您的环境中工作?您正在上载并插入数据库?还是有什么问题?或者您只需要有关文件大小的信息?你能具体说明一下吗?很抱歉回复晚了。。我试过了,但还是有例外。。我对这项技术还不熟悉..\它不应该像你说的那样,因为我已经用过很多次了。若表单提交正在工作,并且函数正在服务器端调用,那个么您可以通过上下文获取任何组件。通过提供组件名称进行请求。请再试一次,否则我稍后会给出完整的代码。调试时,aspx文件中的断点未命中,它表示此文档未加载任何符号。我已测试了您的JS代码,您的JS代码中没有错误。只需检查您使用的xtype:“表单”和URL是否正确。如果你仍然不能解决这个问题,那么我给你代码。您正在将服务器发送到aspx,但我在上传文件后尝试了ashx(服务器端代码的普通处理程序),当您单击“上载”按钮时,只需尝试将请求发送到ashx而不是aspx,断点肯定会被击中。如果您仍然面临问题,请告诉我。
uploadFile.InputStream
uploadFile.FileName
and all others.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script src="Libraries/ext-all.js"></script>
    <script src="Libraries/ext-all-debug.js"></script>
    <link href="Libraries/ext-theme-crisp-all-debug.css" rel="stylesheet" />

    <script type="text/javascript">

        Ext.onReady(function () {
            var window = new Ext.Window({
                id: 'grdWindow',
                width: 400,
                items: [
                    {
                        xtype: 'form',
                        renderTo: Ext.getBody(),
                        items: [
                            {
                                xtype: 'filefield',
                                id: 'AttachData',
                                name: 'file-path',
                                emptyText: 'Upload the document...',
                                margin: "15 0 0 0",
                                buttonText: 'Browse1',
                                msgTarget: 'side',
                                allowBlank: false,
                                anchor: '100%',
                                disabled: false
                            }, {
                                xtype: 'button',
                                text: 'Upload',
                                handler: function () {
                                    var form = this.up('form').getForm();
                                    if (form.isValid()) {
                                        form.submit({
                                            url: 'Default.aspx',
                                            headers: {
                                                'Content-type': 'application/json;charset=utf-8'
                                            },
                                            waitMsg: 'Uploading your file...',
                                            success: function (response, action) {
                                                isUploded = true;
                                                msg('Success', 'Processed file "' + action.result.file + '" on the server');
                                            },
                                            failure: function (response, action) {
                                                console.log(action);
                                                Ext.Msg.alert('Failed', response.message ? action.result.message : 'No response');
                                            }
                                        });
                                    }
                                }
                            }
                        ]
                    }
                ]
            }).show();
        });

        </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    </div>
    </form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpPostedFile fileUpload =  HttpContext.Current.Request.Files["file-path"];
        if (fileUpload != null)
        { 
            //You can get here anything from fileUpload
        }
    }

}