In Extjs, there is no good way to upload files to extended components. There are also many different methods available on the Internet. I use Ext. ux. UploadDialog.
Reference xml code in the file
- <Script type = "text/javascript" src = "lib/extjs. ux/Ext. ux. UploadDialog. js"> </script>
- <Script type = "text/javascript" src = "lib/extjs. ux/Ext. ux. ProgressBar. js"> </script>
- <Link rel = "stylesheet" type = "text/css" href = "css/Ext.ux.ProgressBar.css"/>
- <Link rel = "stylesheet" type = "text/css" href = "css/Ext.ux.UploadDialog.css"/>
Then add the following JavaScript code to the js Code:
- Var dialog = new Ext. ux. UploadDialog. Dialog (null ,{
- AutoCreate: true,
- Closable: true,
- Collapsible: false,
- Draggable: true,
- MinWidth: 400,
- MinHeight: 200,
- Width: 400,
- Height: 350,
- Permitted_extensions: ['jpg ', 'jpg', 'jpeg ', 'jpeg', 'gif', 'gif'],
- ProxyDrag: true,
- Resizable: true,
- Constraw.viewport: true,
- Title: 'file upload ',
- Url: 't_ file_upload.php ',
- Reset_on_hide: false,
- Allow_close_on_upload: true
- });
When the upload button is clicked, the upload dialog box is displayed: js Code
- BtnUpload. on ("click", function (){
- Dialog. show ();
- });
The following is how to process uploaded operations in the t_file_upload.php file: java code
- <? Php
- $ File = "";
- $ Result = array ();
- $ Ext = strrchr ($ _ FILES ["file"] ["name"], '.');
- $ File = "". date ("YmdHis"). $ ext;
- If (move_uploaded_file ($ _ FILES ["file"] ["tmp_name"], "images/upload/". $ file )){
- $ Result = array ('success' => true, data => $ file );
- } Else {
- $ Result = array ('success' => false, 'error' => 'file upload error ');
- }
- Echo json_encode ($ result );
- ?>
The content of the uploaded file is file, which is required :)
The attachment uploads the component library.
- Ext.ux.UploadDialog.zip (16 KB)
- Description: Component Library.