Steps to create File Upload field using Ext Js
As far as specific steps are concerned, using functionality supported in ExtJS 3x, your best best is to use this module/plugin:
http://dev.sencha.com/deploy/dev/examples/form/file-upload.html
The core script comes with the Ext JS package, in your main HTML file (where you have linked to the core Ext scripts), in the head section after your other scripts put:
<script type="text/javascript" src="nameofyourextfolder/examples/ux/fileuploadfield/FileUploadField.js"></script>
Sadly, there isnt a huge amount of documentation on this element of Ext JS- however for basic functionality, you can create a form with an async upload field using the below:
myuploadform= new Ext.FormPanel({ fileUpload: true, width: 500, autoHeight: true, bodyStyle: 'padding: 10px 10px 10px 10px;', labelWidth: 50, defaults: { anchor: '95%', allowBlank: false, msgTarget: 'side' }, items:[ { xtype: 'fileuploadfield', id: 'filedata', emptyText: 'Select a document to upload...', fieldLabel: 'File', buttonText: 'Browse' }], buttons: [{ text: 'Upload', handler: function(){ if(myuploadform.getForm().isValid()){ form_action=1; myuploadform.getForm().submit({ url: 'handleupload.php', waitMsg: 'Uploading file...', success: function(form,action){ msg('Success', 'Processed file on the server'); } }); } } }] })
What this code will do is create a new formpanel with an upload field and an upload button. When you click the upload button- the selected file will be sent to the serverside script handleupload.php (or whatever you call it). It is then this script that handles what you want to do with the file. An example of this could potentially be:
$fileName = $_FILES['filedata']['name']; $tmpName = $_FILES['filedata']['tmp_name']; $fileSize = $_FILES['filedata']['size']; $fileType = $_FILES['filedata']['type']; $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); $content = addslashes($content); fclose($fp); if(!get_magic_quotes_gpc()){ $fileName = addslashes($fileName); } $query = "INSERT INTO yourdatabasetable (`name`, `size`, `type`, `file`) VALUES ('".$fileName."','".$fileSize."', '".$fileType."', '".$content."')"; mysql_query($query);
Which would inject the file into a SQL DB. The thing to remember is the server side file handles an upload just as a normal HTML form would...
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With