Wednesday, May 16, 2012

Simple file upload with php and ExtJs not working

I need the simplest solution for uploading file from Ext application with php. I'm a total php newbie, so I don't get the errors I'm recieving and can only guess what's causing them. On the frontend side I have a simple form :

Ext.create('Ext.form.Panel', {
width: 300,
renderTo: Ext.getBody(),
frame: false,
title: 'File Upload Form',
bodyPadding: '10 10 0',

defaults: {
anchor: '100%',
allowBlank: false,
msgTarget: 'side',
labelWidth: 50

items: [{
xtype: 'filefield',
id: 'form-file',
emptyText: 'Select mpp file',
fieldLabel: 'File',
name: 'mpp-file',
buttonText: '',
buttonConfig: {
iconCls: 'upload-icon'
buttons: [{
text: 'Upload',
handler: function(){
var form = this.up('form').getForm();
url: 'msp-load.php',
waitMsg: 'Loading data...',
success: function(fp, o) {
msg('Success', 'Data from .mpp file loaded ');

The msp-upload.php looks as follows :

$file_tmp = $_FILES['mpp-file']['tmp_name'];
$file_name = $_FILES['mpp-file']['name'];
$file_size = $_FILES['mpp-file']['size'];

//echo ($file_tmp.", ".$file_name.", ".$file_size);

if(is_uploaded_file($file_tmp)) {
if(move_uploaded_file($file_tmp, "tmp/$file_name")){
echo '{success: true}';
} else {
echo '{success: false}';
} else{
echo '{success: false}';

After clicking 'Upload' I get :

uncaught exception: Ext.JSON.decode():
You're trying to decode an invalid JSON String:
<br> <b>Warning</b>: move_uploaded_file(tmp/MSP1.mpp) [<a href="function.move-uploaded-file">function.move-uploaded-file</a>]: failed to open stream: No such file or directory in <b>/Library/WebServer/Documents/examples/MSProject_import/msp-load.php</b> on line <b>10</b><br>
<br> <b>Warning</b>: move_uploaded_file() [<a href="function.move-uploaded-file">function.move-uploaded-file</a>]: Unable to move '/private/var/tmp/phpJVDktB' to 'tmp/MSP1.mpp' in <b>/Library/WebServer/Documents/examples/MSProject_import/msp-load.php</b> on line <b>10</b><br> {success: false}

Where does this : 'No such file...' error come from? It can't find the uploaded file, or something else? My server user has admin privileges so it's not about permissions.

I'm using built-in OSX 10.7 server with PHP 5.3.6 . No errors in the error.log .

No comments:

Post a Comment