views:

160

answers:

2

Hello, I use the UploadFile example in EXTJS (http://dev.sencha.com/deploy/dev/examples/form/file-upload.html) but I don't know what to write in the server side to save the uploaded file (in php) help me please

My client side code is :

var fp = new Ext.FormPanel({
//renderTo: 'fi-form',
fileUpload: true,
width: 500,
frame: true,
title: 'File Upload Form',
autoHeight: true,
bodyStyle: 'padding: 10px 10px 0 10px;',
labelWidth: 50,
defaults: {
    anchor: '95%',
    allowBlank: false,
    msgTarget: 'side'
},
items: [{
    xtype: 'fileuploadfield',
    id: 'form-file',
    emptyText: 'Select an image',
    fieldLabel: 'Photo',
    name: 'photo-path',
    buttonText: '',
    buttonCfg: {
        iconCls: 'upload-icon'
    }
}],
buttons: [{
    text: 'Save',
    handler: function(){
        if(fp.getForm().isValid()){
                fp.getForm().submit({
                    url: 'php/file-upload.php',
                    waitMsg: 'Uploading your photo...',
                    success: function(fp, o){
                        msg('Success', 'Processed file');
                    }
                });
        }
    }
},{
    text: 'Reset',
    handler: function(){
        fp.getForm().reset();
    }
}]

});

+1  A: 

Here is a example, you can use it and customize based on your needs.

if(isset($_FILES)){
  $temp_file_name = $_FILES['your_file']['tmp_name'];
  $original_file_name = $_FILES['your_file']['name'];

  // Find file extention
  $ext = explode ('.', $original_file_name);
  $ext = $ext [count ($ext) - 1];

  // Remove the extention from the original file name
  $file_name = str_replace ($ext, '', $original_file_name);

  $new_name = '_'.$file_name . $ext;

  if (move_uploaded_file ($temp_file_name, $new_name)) {
      echo "success";
   } else {
      echo "error";
    }

}
Centurion
The problem is that in my client, the upload is always running, but I don't have any thing in my server
taichimaro
+1  A: 

See the following for help on AJAX file upload in PHP:

http://www.anyexample.com/programming/php/php_ajax_example__asynchronous_file_upload.xml http://www.ajaxf1.com/tutorial/ajax-file-upload-tutorial.html

Todd Moses