PDA

View Full Version : why php $_FILES is empty whe uploading form via api ??



maneljn
4 Sep 2012, 8:17 AM
Extjs 4.1.1 RC2

When i upload a file, i receive an empty $_FILES in PHP

I have this form:


// Formulario para subir la foto
xtype: 'form',
name: 'formularioSubirFoto',
title: '',
bodyPadding: 5,
border: false,
anchor: '100%',
api: {
submit: Ext.esicontactosDirect.esicontactos_contactos.subirFotoContacto
},
items: [{
xtype: 'filefield',
name: 'fotocontacto',
fieldLabel: gt.dgettext('esicontactos','Foto'),
labelWidth: 50,
msgTarget: 'side',
allowBlank: true,
anchor: '100%',
buttonOnly: false,
buttonText: gt.dgettext('esicontactos','Seleccione una imagen...')
}]


And this is the submit process in mvc controller


formularioSubirFoto.getForm().submit({
params: {
cto_id: cto_id,
cto_guid: cto_guid
},
waitMsg: gt.dgettext('esicontactos','Subiendo foto al servidor ... '),
success: function(form, action) {
console.log("success");
},
failure: function(form, action) {
console.log("failure");
}
});


This is the php code that receives the extdirec api call


/**
* Subir la foto de un Contacto
* Este metodo tiene que estar agregado en la funcion esValido del esicontactos_uploader
* @remotable
* @formHandler
*/
public static function subirFotoContacto( $_parametros, $_archivos )
{

var_dump($_parametros);
var_dump("<br />");
var_dump($_archivos['fotocontacto']['tmp_name']);
var_dump("<br />");
var_dump($_archivos);
var_dump("<br />");
var_dump($_FILES);
var_dump("<br />");

...................



This is the post view in firebug


Encabezados de respuestaver fuente



Cache-Control
no-store, no-cache, must-revalidate, post-check=0, pre-check=0


Connection
close


Content-Type
text/html


Date
Tue, 04 Sep 2012 16:05:37 GMT


Expires
Thu, 19 Nov 1981 08:52:00 GMT


Pragma
no-cache


Server
Apache


Transfer-Encoding
chunked


Encabezados de solicitudver fuente


Accept
text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8


Accept-Encoding
gzip, deflate


Accept-Language
es-es,es;q=0.8,en-us;q=0.5,en;q=0.3


Connection
keep-alive


Cookie
__utma=70484738.1139431865.1346054497.1346138584.1346417597.3; __utmz=70484738.1346054497.1.1.utmcsr=esigest.com|utmccn=(referral)|utmcmd=referral|utmcct=/; PHPSESSID=oj5enn5ti4uvsts1flfbi601o7


Host
www.cesilabs.com


Referer
https://www.cesilabs.com/esinube_desarrollo/aplicaciones/esicontactos/?desarrollo


User-Agent
Mozilla/5.0 (Windows NT 6.1; rv:14.0) Gecko/20100101 Firefox/14.0.1 FirePHP/0.7.1


x-insight
activate




Encabezados de respuesta de datos enviados


Content-Length
793


Content-Type
multipart/form-data; boundary=---------------------------64222494627506





The response in php



array(7) { ["cto_id"]=> string(1) "1" ["cto_guid"]=> string(13) "4f67784c0ae0e" ["extTID"]=> string(2) "11" ["extAction"]=> string(22) "esicontactos_contactos" ["extMethod"]=> string(17) "subirFotoContacto" ["extType"]=> string(3) "rpc" ["extUpload"]=> string(4) "true" } string(6) "<br />" NULL string(6) "<br />" array(0) { } string(6) "<br />" array(0) { } string(6) "<br />" <html><body><textarea>{"type":"rpc","tid":"11","action":"esicontactos_contactos","method":"subirFotoContacto","result":{"success":true}}</textarea></body></html>



Please help, i'm going crazy. :-((

scottmartin
4 Sep 2012, 9:19 AM
Specify the url in your submit and see if you get a value:


$_FILES['file']['name']



form.getForm().submit({
url: 'upload_file.php',
waitMsg: 'Uploading ...',
success: function(fp, o){
me.close();
}
});


Scott.

maneljn
4 Sep 2012, 9:38 AM
Scott, i put this in index.php



var_dump("hello");
var_dump($_FILES);
var_dump($_FILES['fotocontacto']['name']);
die;


and have deleted in form the api config, and put url in submit


formularioSubirFoto.getForm().submit({
url: 'index.php',
params: {
cto_id: cto_id,
cto_guid: cto_guid
},
waitMsg: gt.dgettext('esicontactos','Subiendo foto al servidor ... '),
success: function(form, action) {
console.log("success");
//Ext.Msg.alert('Success', action.result.msg);
},
failure: function(form, action) {
console.log("failure");
}
});



The result is also empty $_FILES
I'm sure that i'm selecting an small .txt file to upload (100Kb)




string(5) "hello" array(0) { } NULL

maneljn
5 Sep 2012, 7:41 AM
could it be a bug in extjs 4.1.1 rc2 ?¿
Extdirect form post (file upload) doesn't send the content of uploaded file in post firebug analysis

I've read a bug similar in this post...
http://www.sencha.com/forum/showthread.php?185103-4.1rc1-ExtDirect-Form-Post-%28File-Upload%29-doesn-t-work-since-4.1&p=882708

scottmartin
5 Sep 2012, 10:56 AM
Please upgrade and report back. 4.1.1 has been released and you should not be using rc2

Scott.

maneljn
5 Sep 2012, 11:47 PM
Please upgrade and report back. 4.1.1 has been released and you should not be using rc2

Scott.


Scott, i have upgraded to extjs 4.1.1 , and tested again.
The same result.
Analyzing post with firebug, it doesn't send any file.
In php i found $_FILES as an empty array()

maneljn
5 Sep 2012, 11:57 PM
Scott, i think that probably the problem could be in another piece of code. I'm analysing it. Before to upload the file, i'm saving a model record. I try changing code structure and reporting back.

maneljn
6 Sep 2012, 1:08 AM
Scott,

I want to apologize for having wasted your time. Your suggestion to update to version 4.1.1 allowed me to see that the problem with the upload, it I had elsewhere in my code that destroyed the form in a previous save to submit the upload. Sorry, and thanks for your help.

I can confirm that there is no bug with submit api upload and extjs 4.1.1
It works fine.

scottmartin
7 Sep 2012, 9:44 AM
Thank you for the update. All is well.

Scott.