PDA

View Full Version : Success function in formPanel is not executed after successfull file upload



zagreberlin
6 Sep 2011, 11:26 PM
Hi people,

i dont know where the problem is. I am trying to implement a file upload.
everything worked fine but now, i dont know why, it redirects me to the php-file which executes the file upload but it remains on the php-file and dont redirect it back to my html file which contains the JS Code.
So the success-method in the formPanel will not be executed but i dont know why. yesterday it was all ok but now it redirects me to the fileuploading.php where i stay and dont go back to my html.
what could be the reason?
Please help!

This is my JS-Code


var panelRightTop = new Ext.FormPanel({
title : 'Upload Files',
width : 360,
renderTo : 'right-top',
standardSubmit : true,
buttonAlign: 'center',
labelWidth : 30,
fileUpload : true,

frame : true,
items: [
{
xtype: 'fileuploadfield',
emptyText: '',
fieldLabel: 'Image 1',
buttonText: 'Select a File',
width : 350,
name: 'img[]'
}, {
xtype: 'fileuploadfield',
emptyText: '',
fieldLabel: 'Image 2',
buttonText: 'Select a File',
width: 350,
name: 'img[]'
}, ],
buttons: [{
text: 'Upload',
handler: function() {
panelRightTop.getForm().submit({
url: 'FileUploading.php',
waitMsg: 'Uploading ....',
success: function(form, o) {
Ext.MessageBox.alert('Success', 'Processed file on the server');
panelRightTop.getForm().reset();
//store.load();
}
});
}
}, {
text: 'Reset',
handler: function() {

Ext.MessageBox.alert('Reset Button');
panelRightTop.getForm().reset();
}
}]
});


Code of the FileUploading.php


$allowedType = array( 'image/jpeg', 'image/pjpeg', 'image/png', 'image/gif', 'image/x-png' );

foreach($_FILES['img']['name'] as $key => $img) { if (in_array($_FILES['img']['type'][$key], $allowedType)) {
move_uploaded_file($_FILES['img']['tmp_name'][$key], 'Uploads/'.$_FILES['img']['name'][$key]); } }

syl_via38
6 Sep 2011, 11:47 PM
Hello,

I am very newbie in extjs, but in my php code, at the end, usually I put something like :

die('{ "success":true,"message":""}');

Syl

zagreberlin
7 Sep 2011, 1:58 AM
Thank you syl_via38 for the reply but it dont work.

syl_via38
7 Sep 2011, 2:18 AM
Here is example of my code that it works fine :



handler:function(){
if (conn.form.isValid()) {

conn.getForm().submit({
method :'POST',

failure: function(result, action) {
Ext.MessageBox.show({
title: 'Connect',
msg: action.result.message,
buttons: Ext.Msg.OK,
icon: Ext.MessageBox.ERROR
});
},

success: function(result, action) {
Ext.MessageBox.show({
title: 'Success',
msg: action.result.message,
buttons: Ext.Msg.OK,
icon: Ext.MessageBox.INFO
});

}
});
}
}



/*your code here*/

die('{ "success":false, "message":'Not connected'}');

zagreberlin
7 Sep 2011, 6:20 AM
Hey syl_via38,

the problem was the
standardSubmit: true.
If its true it dont redirect you back from the php file to the html-file which calls the php.
If its false the success : function of the button will be executed.
thanks again!