PDA

View Full Version : Unable to upload files



cub3D
28 Aug 2012, 2:36 AM
Hi there,


First: thank you for your work. Extjs is great!


It's my first post here and I'm French, so please forgive me if I'm not explaining myself very well.


I have written a big MVC application using Extjs 4.1 that works well enough. But I'm trying to use a form with the "filefield" control and I can't figure how to have it work properly, even after having spent some days reading all I could find in the forums etc. The $_FILE array in the php backend always comes empty.


Here is the view file containing the form.




Ext.define('Appli.view.CreFiche', {
extend: 'Ext.window.Window',
alias: 'widget.crefiche',
closable : false,
initComponent: function() {
var me = this;
Ext.applyIf(me,{
layout : 'fit',
id : 'cref',
title : 'Création fiche PDF',
header : true,
width : 400,
autoheight : true,
closeAction : 'close',
plain : true,
draggable : true,
border : 0,
resizable : false,
collapsible : false,
shadow : true,
modal : true,
items: [{
xtype: 'form',
id:'myCFiche',
bodyStyle:'padding:10px 10px 10px 10px;background-color:#DBE1E9;background-image: none;',
fieldDefaults: {
labelAlign: 'top',
labelSeparator:':',
labelWidth: 120
},
border:false,
width: 400,
items: [{
xtype: 'filefield',
id: 'lien',
name:'lien',
emptyText: 'Selectionnez une fiche PDF',
fieldLabel: 'Fichier',
anchor: '100%',
buttonText: '',
buttonConfig: {
iconCls: 'upload-icon'
}
}],
buttons: [{
text: 'Copier',
handler: function() {
var form = this.up('form').getForm();
if(form.isValid()){
form.submit({
url: 'php/crefiche.php',
waitMsg: 'Patientez...',
standardSubmit:true,
success: function(fp, o) {
Ext.Msg.alert('Success', 'Votre fichier "' + o.result.file + '" a été copié.');
}
});
}
}
},{
text: 'Reset',
id: 'raz',
tooltip:'Vider le formulaire'
},{
text: 'Quitter',
id: 'exit',
tooltip:'Fermer le formulaire'
}]
}]
});
me.callParent(arguments);
}
});


I've probably overlooked something big but I'm lost.

Here is what I get in Firebug (Network, all, post) when I try to upload a text file:



Source
-----------------------------126232408419954Content-Disposition: form-data; name="lien"; filename="last.txt"Content-Type: text/plain 20ContentsTHE LAST PLACE ON EARTH.....................................................1Scott and Amundsen's Race to the South Pole..............................1Roland Huntford............................................................................4Introduction to the Modern Library Exploration Series...............7Introduction.................................................................................10 Acknowledgments.........................................................................17Contents.......................................................................................20 Author’s note................................................................................22PART ONE...................................................................................24CHAPTER 01 - Rivals for the Pole...............................................25CHAPTER 02 - The Forerunners................................................26CHAPTER 03 - "The Last of the Vikings"...................................33CHAPTER 04 - The Nansen Spirit..............................................40CHAPTER 05 -
.
.
content of the text file continues for a while
.
.
-----------------------------126232408419954--


I get an error message from the php file " Notice: Undefined index: file in C:\wamp\www\Emma\php\crefiche.php on line 5" when I try to parse the $_FILE array.

I'd be very grateful for some help.

Thanks in advance

Sylvie

cub3D
28 Aug 2012, 3:30 AM
I'm sorry, it was as big as expected.

I just got confused by the word 'file' in $_FILES['file']['name'] in the examples. I didn't realize that it had to be the name of my file field (in my case 'lien').

Everything works fine now.

Best regards and thanks for the great work you do here.

Sylvie