Templates y Temas para ExtJS y Sencha Touch Bleext!
Bleextop! un desktop OpenSource para Ext4 y CodeIgniter http://bit.ly/pUwLJO
Subir un archivo al servidor con Extjs
  • Vote Up1Vote Down duvan1124duvan1124 October 2009
    Posts: 78
    Hola amigos el dia de hoy tengo una gran duda, quisiera saber si es posible subir un archivo al servidor utilizando la libreria Extjs y mirar algunos ejemplos...

    de antemano muchas gracias por su ayuda amigos....
  • 15 Answers sorted by
  • Vote Up0Vote Down elcrespoelcrespo October 2009
    Posts: 158
    subir como tal no, para eso necesitas hacerlo con un lenguaje del lado del servidor como php, jsp, etc... lo que si puedes hacer es colocar el formulariio con un xtype: textfield, con un inputType: 'file' y al formpanel colocarle fileUpload: true... con eso puedes recibir del lado servidor el archivo que escogiste en el formulario y guradarlo donde quieras.
  • Vote Up0Vote Down duvan1124duvan1124 October 2009
    Posts: 78
    ahhhhhhhhhhhhhhhhhh gracias graciassssss amigoooo...... muchas gracias... una ves del ladoo del servidor ya es facil subir el archivo..
  • Vote Up0Vote Down duvan1124duvan1124 October 2009
    Posts: 78
    Amigo he probado al subir el archivo pero lastimosamente no lo hace efectivo.... aqui dejo mi codigo para que me ayuden porque cuando envio el formulario no esta recibiendo el archivo del lado del servidor.... de antemano muchas gracias por su ayuda

    function cargarclientes(){

    this.form = new Ext.form.FormPanel({
    url: 'cargar.php',
    width:330,
    bodyStyle:'margin-left:10px;',
    border:false,
    waitMsgTarget: true,
    labelWidth: 50,
    items:[
    {xtype:'textfield',fieldLabel:'Archivo', inputType: 'file', fileUpload: true, name:'archivo', width:200, allowBlank:false}

    ]
    });

    this.cargar= function()
    {

    this.form.getForm().submit(
    {
    waitMsg:'Cargando...',
    success: function(f,a)
    {
    Ext.Msg.show({
    title: 'Cargando', //<- el título del diálogo
    msg: 'Archivo Cargado Correctamente !!', //<- El mensaje
    buttons: Ext.Msg.OK, //<- Boton de Aceptar
    icon: Ext.Msg.INFO // <- un ícono de Info
    });

    //this.form.getForm().reset();
    wine.close();

    },

    failure: function(f,a)
    {
    Ext.Msg.show({
    title: 'Error', //<- el título del diálogo
    msg: a.result.errormsg, //<- El mensaje
    buttons: Ext.Msg.OK, //<- Boton de Aceptar
    icon: Ext.Msg.ERROR // <- un ícono de Info
    });
    }
    }
    );//submit
    }//cargar


    var winc;

    if(!winc){

    winc = new Ext.Window({


    title: '.: Cargar Clientes :.',
    bodyStyle: 'padding:10px;background-color:#fff;',
    width:315,
    height:150,
    modal:true,
    buttons: [{text:'Cargar',handler:this.cargar,scope:this}],
    items:[this.form]
    });

    }
    winc.show(this);
    }
  • Vote Up0Vote Down elcrespoelcrespo October 2009
    Posts: 158
    esta parte del código : fileUpload&#58; true debes dejarla en el formulario no en el textfield... trata con eso y nos avisas
  • Vote Up0Vote Down duvan1124duvan1124 October 2009
    Posts: 78
    Nooo amigooo ya lo puse el fileUpload en el form y tampoco funciona aqui dejo mi codigo....

    muchas gracias por su ayuda...


    function cargarclientes(){

    this&#46;form = new Ext&#46;form&#46;FormPanel({
    url&#58; 'cargar&#46;php',
    width&#58;330,
    bodyStyle&#58;'margin-left&#58;10px;',
    border&#58;false,
    waitMsgTarget&#58; true,
    labelWidth&#58; 50,
    fileUpload&#58; true,
    items&#58;&#91;
    {xtype&#58;'textfield',
    fieldLabel&#58;'Archivo',
    inputType&#58;'file',
    name&#58;'archivo',
    emptyText&#58; 'Debe seleccionar un archivo',
    width&#58;200}
    &#93;
    });

    this&#46;cargar= function()
    {

    this&#46;form&#46;getForm()&#46;submit(
    {
    waitMsg&#58;'Cargando&#46;&#46;&#46;',
    success&#58; function(f,a)
    {
    Ext&#46;Msg&#46;show({
    title&#58; 'Cargando', //&lt;- el título del diálogo
    msg&#58; 'Archivo Cargado Correctamente !!', //&lt;- El mensaje
    buttons&#58; Ext&#46;Msg&#46;OK, //&lt;- Boton de Aceptar
    icon&#58; Ext&#46;Msg&#46;INFO // &lt;- un ícono de Info
    });


    winc&#46;close();

    },

    failure&#58; function(f,a)
    {
    Ext&#46;Msg&#46;show({
    title&#58; 'Error', //&lt;- el título del diálogo
    msg&#58; a&#46;result&#46;errormsg, //&lt;- El mensaje
    buttons&#58; Ext&#46;Msg&#46;OK, //&lt;- Boton de Aceptar
    icon&#58; Ext&#46;Msg&#46;ERROR // &lt;- un ícono de Info
    });
    }
    }
    );//submit
    }//cargar


    var winc;

    if(!winc){

    winc = new Ext&#46;Window({

    title&#58; '&#46;&#58; Cargar Clientes &#58;&#46;',
    bodyStyle&#58; 'padding&#58;10px;background-color&#58;#fff;',
    width&#58;315,
    height&#58;150,
    x&#58;50,
    y&#58;50,
    modal&#58;true,
    buttons&#58; &#91;{text&#58;'Cargar',handler&#58;this&#46;cargar,scope&#58;this}&#93;,
    items&#58;&#91;this&#46;form&#93;
    });

    }
    winc&#46;show(this);
    }
  • Vote Up0Vote Down duvan1124duvan1124 October 2009
    Posts: 78
    Amigos les pido su ayuda ya que necesito cargar un archivo con urgencia y no he podido hacerlo en el anterior mensaje deje mi codigo...

    De antemano muchas gracias...
  • Vote Up0Vote Down CrysfelCrysfel October 2009
    Posts: 897
    utiliza este plugin:


    /*!
    * Ext JS Library 3&#46;0+
    * Copyright(c) 2006-2009 Ext JS, LLC
    * licensing@extjs&#46;com
    * http&#58;//www&#46;extjs&#46;com/license
    */
    Ext&#46;ns('Ext&#46;ux&#46;form');

    /**
    * <a href="/profile/class">@class</a> Ext&#46;ux&#46;form&#46;FileUploadField
    * <a href="/profile/extends">@extends</a> Ext&#46;form&#46;TextField
    * Creates a file upload field&#46;
    * <a href="/profile/xtype">@xtype</a> fileuploadfield
    */
    Ext&#46;ux&#46;form&#46;FileUploadField = Ext&#46;extend(Ext&#46;form&#46;TextField, {
    /**
    * <a href="/profile/cfg">@cfg</a> {String} buttonText The button text to display on the upload button (defaults to
    * 'Browse&#46;&#46;&#46;')&#46; Note that if you supply a value for {@link #buttonCfg}, the buttonCfg&#46;text
    * value will be used instead if available&#46;
    */
    buttonText&#58; 'Browse&#46;&#46;&#46;',
    /**
    * <a href="/profile/cfg">@cfg</a> {Boolean} buttonOnly True to display the file upload field as a button with no visible
    * text field (defaults to false)&#46; If true, all inherited TextField members will still be available&#46;
    */
    buttonOnly&#58; false,
    /**
    * <a href="/profile/cfg">@cfg</a> {Number} buttonOffset The number of pixels of space reserved between the button and the text field
    * (defaults to 3)&#46; Note that this only applies if {@link #buttonOnly} = false&#46;
    */
    buttonOffset&#58; 3,
    /**
    * <a href="/profile/cfg">@cfg</a> {Object} buttonCfg A standard {@link Ext&#46;Button} config object&#46;
    */

    // private
    readOnly&#58; true,

    /**
    * <a href="/profile/hide">@hide</a>
    * <a href="/profile/method">@method</a> autoSize
    */
    autoSize&#58; Ext&#46;emptyFn,

    // private
    initComponent&#58; function(){
    Ext&#46;ux&#46;form&#46;FileUploadField&#46;superclass&#46;initComponent&#46;call(this);

    this&#46;addEvents(
    /**
    * <a href="/profile/event">@event</a> fileselected
    * Fires when the underlying file input field's value has changed from the user
    * selecting a new file from the system file selection dialog&#46;
    * <a href="/profile/param">@param</a> {Ext&#46;ux&#46;form&#46;FileUploadField} this
    * <a href="/profile/param">@param</a> {String} value The file value returned by the underlying file input field
    */
    'fileselected'
    );
    },

    // private
    onRender &#58; function(ct, position){
    Ext&#46;ux&#46;form&#46;FileUploadField&#46;superclass&#46;onRender&#46;call(this, ct, position);

    this&#46;wrap = this&#46;el&#46;wrap({cls&#58;'x-form-field-wrap x-form-file-wrap'});
    this&#46;el&#46;addClass('x-form-file-text');
    this&#46;el&#46;dom&#46;removeAttribute('name');

    this&#46;fileInput = this&#46;wrap&#46;createChild({
    id&#58; this&#46;getFileInputId(),
    name&#58; this&#46;name||this&#46;getId(),
    cls&#58; 'x-form-file',
    tag&#58; 'input',
    type&#58; 'file',
    size&#58; 1
    });

    var btnCfg = Ext&#46;applyIf(this&#46;buttonCfg || {}, {
    text&#58; this&#46;buttonText
    });
    this&#46;button = new Ext&#46;Button(Ext&#46;apply(btnCfg, {
    renderTo&#58; this&#46;wrap,
    cls&#58; 'x-form-file-btn' + (btnCfg&#46;iconCls ? ' x-btn-icon' &#58; '')
    }));

    if(this&#46;buttonOnly){
    this&#46;el&#46;hide();
    this&#46;wrap&#46;setWidth(this&#46;button&#46;getEl()&#46;getWidth());
    }

    this&#46;fileInput&#46;on('change', function(){
    var v = this&#46;fileInput&#46;dom&#46;value;
    this&#46;setValue(v);
    this&#46;fireEvent('fileselected', this, v);
    }, this);
    },

    // private
    getFileInputId&#58; function(){
    return this&#46;id + '-file';
    },

    // private
    onResize &#58; function(w, h){
    Ext&#46;ux&#46;form&#46;FileUploadField&#46;superclass&#46;onResize&#46;call(this, w, h);

    this&#46;wrap&#46;setWidth(w);

    if(!this&#46;buttonOnly){
    var w = this&#46;wrap&#46;getWidth() - this&#46;button&#46;getEl()&#46;getWidth() - this&#46;buttonOffset;
    this&#46;el&#46;setWidth(w);
    }
    },

    // private
    onDestroy&#58; function(){
    Ext&#46;ux&#46;form&#46;FileUploadField&#46;superclass&#46;onDestroy&#46;call(this);
    Ext&#46;destroy(this&#46;fileInput, this&#46;button, this&#46;wrap);
    },


    // private
    preFocus &#58; Ext&#46;emptyFn,

    // private
    getResizeEl &#58; function(){
    return this&#46;wrap;
    },

    // private
    getPositionEl &#58; function(){
    return this&#46;wrap;
    },

    // private
    alignErrorIcon &#58; function(){
    this&#46;errorIcon&#46;alignTo(this&#46;wrap, 'tl-tr', &#91;2, 0&#93;);
    }

    });

    Ext&#46;reg('fileuploadfield', Ext&#46;ux&#46;form&#46;FileUploadField);

    // backwards compat
    Ext&#46;form&#46;FileUploadField = Ext&#46;ux&#46;form&#46;FileUploadField;



    y lo usarias algo así:


    {
    xtype&#58; 'fileuploadfield',
    id&#58; 'form-file',
    emptyText&#58; 'Select an image',
    fieldLabel&#58; 'Photo',
    name&#58; 'photo-path',
    buttonText&#58; '',
    buttonCfg&#58; {
    iconCls&#58; 'upload-icon'
    }
    }


    aqui checa el ejemplo: http://www.extjs.com/deploy/dev/example ... pload.html

    Saludos y suerte
  • Vote Up0Vote Down duvan1124duvan1124 October 2009
    Posts: 78
    Bien muchisimass graciasss stock mirare como me va con el plugin...

    Gracias...
  • Vote Up0Vote Down duvan1124duvan1124 October 2009
    Posts: 78
    Listo....

    con la ayuda de stock logre subir el archivo al servidor

    muchas gracias...
  • Vote Up0Vote Down CrysfelCrysfel October 2009
    Posts: 897
    que bien!!

    saludos
  • Vote Up0Vote Down prue86prue86 November 2009
    Posts: 1
    hola soy nueva en este foro y estoy aprendiendo a programar en extjs estoy n l mismo dilema no puedo subir un archivo al servidor quiero usar tu plugin pero en verdad no c en donde ubicarlo y como llamarlo por favor m prodrian ayudar de antemano muchas gracias...
  • Vote Up0Vote Down CrysfelCrysfel November 2009
    Posts: 897
    necesitas importar el código del plugin a tu html y luego lo utilizas así:


    {
    xtype&#58; 'fileuploadfield',
    id&#58; 'form-file',
    emptyText&#58; 'Select an image',
    fieldLabel&#58; 'Photo',
    name&#58; 'photo-path',
    buttonText&#58; '',
    buttonCfg&#58; {
    iconCls&#58; 'upload-icon'
    }
    }


    saludos
  • Vote Up0Vote Down beinbein November 2010
    Posts: 1
    @elcrespo, chingon... ahora ya puedo subir mi archivo :D, felicidades, mañana subo mi solución, utilizando:

    struts
    json
    extjs
    jsp

    saludos desde Puebla, México
  • Vote Up0Vote Down maicol23maicol23 March 5
    Posts: 13
    Hola, realice lo que Crysfel indico en un formulario sencillo, pero me sale mal el boton para cargar el archivo. Adjunto la imagen en donde se ven los errores, si alguien sabe porque ocurre esto les agradezco la ayuda.
    Attachments
    LoadFile.png 18K
  • Vote Up0Vote Down tokkaidotokkaido March 9
    Posts: 395
    creo que tu problema es que no has adjuntado a tu html los css del plugin

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Login with Facebook Sign In with Twitter

Sign In Apply for Membership

In this Discussion

Poll

No poll attached to this discussion.