Flash Percent Uploader with Symfony!
Flash Percent Uploader with Symfony!
I just had to upload 40+mb of video file sizes to one of my recent project, For this purpose using simple form is obviously not a good choice as user never knows how much data has been transferred and how much left. So percent uploader was inevitable here, for this purpose flash offers fileReference class which can be used to upload mutliple files to the server, with this filereference class you can get file size at onSelect event, so you can apply max-upload file size check and as well as you can monitor file transfer with onProgress event. The only problem while implementing the flash percent uploader is that you may recieve message like “A flash script is causing you computer to get slow! Would you like to abort it?”. The best way to avoid this error message is to make flash script busy in doing something else while uploading, it can be as simple as incrementing tmp variable.
Also, you will definitely love to increase upload limit at server, For PHP you will change the following variables:
upload_max_filesize = 50M
post_max_size = 50M
Now it was as simple as it is for the non-symfony apps, The problem of using this with symfony app is that upload() method of fileReference class cannot initiate an action of the symfony application. On calling the action it does nothing, It does not even gives HTTP error 404 or anything like that, means it founds the path to the action (note that upload method returns true), but the action cannot communicate with it. So to overcome this problem, we will write our upload script in a file under web directory and we can call that script directly from the upload() method. like:-
var item:FileReference = new FileReference();
path_to_upload_script = “……/uploader.php”;
item.upload(path_to_upload_script); // note that the parameter path should be absolute
Now you may require to do some database activity, may need to create some criteria and doSelects, wondering if thats possible from the script in the web directory? Then yes its possible, instead using:
sfContext::getInstance()->getController()->dispatch(); // that is used in index.php, we don’t need to dispatch the controller otherwise it will goto default homepage of our symfony app. We just need to get sfContext Instance. like:
sfContext::getInstance();
Now you are ready to go, you can call the script and can communicate with the database as well.
One Comments
I see that you manually add/remove cells, and sets its row spans in the click handlers.
that is not a good way to use gwt, as you did not abstract yourself from html, but is just writing “html” in java.
what you could do is instead define two more widgets – one widget for the collapsed state view, and another for the open state view. how you implement these widgets is up to you, but i would just have another table in there.
then, in each cell of the flex-table you would add in the correct widget when the click happens.
that way, you dont get bogged down in the click handler with table manipulation code.