PDA

View Full Version : Problem with form uploads



brandonc
2 Mar 2011, 9:15 AM
I'm using Ext.ux.form.FileUploadField from the examples folder of my Ext folder. I've got the form sending info to the url I specified, and the proper data is in the $_FILES array. All the upload processing work fine, it renames the file, moves it to the right folder, exactly like it should.

As soon as it reaches the end of the end of the function, I get this error:

XML tag name mismatch (expected img)
chrome://firebug/content/blank.gif(<div style="left: 0px; top: 0px; posi...283px; left: 0px; top: -75px;"></div>


I tried echo '{"success": true}'; but that didn't work. I did read through the docs and since I'm returning json data, I am setting the Content-type to text/html. I am also sending my return data through htmlentities() so it gets escaped properly.

Heres my php file (this is a cakephp app)


function admin_upload() {
FireCake::log($_FILES);

// get the document relative path to the inital storage folder
$abs_path = WWW_ROOT . 'files/public/rfps/';
$rel_path = 'files/public/rfps/';
$file_ext = '';
$filename = '';

FireCake::log('sss all good');
switch($_FILES['file']['type']) {
case 'application/pdf':
$file_ext = '.pdf';
break;
case 'application/msword':
$file_ext = '.doc';
break;
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
$file_ext = '.docx';
break;
}

$filename = date('YmdHis') . $file_ext;

// check to see if the directory exists
if (!is_dir($abs_path)) {
mkdir($abs_path);
}

if (!file_exists($abs_path . $filename)) {
$full_url = $abs_path . $filename;
$url = $rel_path . $filename;

if (!move_uploaded_file($_FILES['file']['tmp_name'], $url)) {
FireCake::log('failing');
$data['success'] = false;
} else {
FireCake::log('didnt fail');
$data['success'] = true;
$data['url'] = $url;
}
}

$this->header('Content-type: text/html');
$this->render(null, null, '/elements/ajaxreturn');
}


Here is the FormPanel


var rfpForm = new Ext.form.FormPanel({
fileUpload: true,
frame:true,
labelWidth: 75,
height: 300,
title: 'Add RFP',
id: 'rfpform',
collapsible: true,
items: [{
layout: 'column',
items: [{
columnWidth: 0.5,
layout: 'form',
items: [{
xtype: 'textfield',
fieldLabel: 'Title',
name: 'title',
allowBlank: false,
width: 200,
anchor: '95%',
vtype: 'alphaspace'
},{
xtype: 'textfield',
fieldLabel: 'Byline',
name: 'byline',
allowBlank: false,
width: 200,
anchor: '95%',
vtype: 'alphaspace'
},{
xtype: 'textfield',
fieldLabel: 'Contact Email',
name: 'contact_email',
allowBlank: false,
width: 200,
anchor: '95%',
vtype: 'email'
}]
},{
columnWidth: 0.5,
layout: 'form',
items: [{
fieldLabel: 'Deadline',
name: 'deadline',
xtype: 'datefield',
width: 200,
anchor: '98%'
},{
fieldLabel: 'Expires',
name: 'expires',
xtype: 'datefield',
width: 200,
anchor: '98%'
},{
fieldLabel: 'File',
name: 'file',
xtype: 'fileuploadfield',
emptyText: 'Please select a document to upload',
width: 200,
anchor: '98%'
}]
}]
},{
xtype: 'htmleditor',
enableFont: false,
allowBlank: false,
fieldLabel: 'Description',
name: 'description',
width: 300,
anchor: '99%'
}],
buttons: [{
text: 'Save',
id: 'saveButton',
handler: function(){
var f = rfpForm.getForm();
if (f.isValid()) {
f.submit({
url: '/admin/rfps/upload',
waitMsg: 'Uploading your file',
success: function(fp, o) {
Ext.Msg.alert('successssszzz');
}
});

// var vals = f.getValues();
// f.reset();
// console.log(vals);
// var Rfp = new grid.store.recordType({
// title: vals.title,
// byline: vals.byline,
// description: vals.description,
// deadline: vals.deadline,
// expires: vals.expires,
// contact_email: vals.contact_email
// });
// store.add(Rfp);
}
}
},{
text: 'Update',
id: 'updateButton',
disabled: true,
handler: function() {
var f = rfpForm.getForm();
if (f.isValid()) {
rec = grid.getSelectionModel().getSelected();
f.updateRecord(rec);
}
}
},{
text: 'Cancel',
id: 'cancelButton',
handler: function() {
Ext.getCmp('updateButton').disable();
Ext.getCmp('saveButton').enable();
rfpForm.getForm().reset();
}
}]
});

brandonc
4 Mar 2011, 7:59 AM
not to bump my own thread, but this is pretty integral piece of the software I'm writing and I can't figure it out for the life of me (:|

brandonc
4 Mar 2011, 7:58 PM
Ok so, I've narrowed it down. All my view code is written in xhtml, with a content-type of text/html.

The hidden iframe that gets generated, posts the request to my admin_upload() method, and it returns the view back into the iframe. So essentially it's parsing an entire layout and it's failing at any tag that is self closing (e.g. br, img, etc).

Even though the tags are closed (e.g. <img .. />) it's looking for ending tags for them.

As stated I've tried with header('Content-type: text/html'), I've tried without. I'm lost for now, I may pull down my code from repo over the weekend to continue trying to fix it.

Does anyone know why this is happening? It might even be an error on my part because that particular method isn't supposed to return a layout, just the json object string.

I'll figure it out eventually, at least posting answers to my own questions may help someone in the future.

:-|

Condor
5 Mar 2011, 4:10 AM
My PHP isn't that good. Can you post what this PHP script actually returns (e.g. copy from the Firebug Net tab)?

It should be returning (any <, > or & needs to be escaped!):

<html><body>{success: true}</body></html>
or (if you don't want to HTML escape the data):

<html><body><textarea>{success: true}</textarea></body></html>