Is it feasible to add support for Webform uploads?
The use-case I'm looking at is basically this: A contract manufacturer needs to accept uploads of design files, which can be quite large. I can imagine variants, such as submitting video or audio works, large photos, Photoshop files, etc.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | progressbar.png | 11.24 KB | andyn_uk |
Comments
Comment #1
andyn_uk commentedI needed a solution for progress bars when uploading files on webforms and first thought about SWFupload, but quickly realised that it wasnt workable in the timescales I had (a couple of hours). I have just hacked together a working system, and thought id share it here. It uses a PECL extension server side and jQuery on the client. No Flash needed at all!
1) Install the UploadProgress PECL extension (see http://freestylesystems.co.uk/blog/installing-pecl-uploadprogress-extens... for instructions on how)
2) create a file on your server called uploadprogress.php (or anything you like but my example assumes this name) with the following content:
2) Add two new fields to your Webform. The first one below MUST be the first field in your Webform! Also make sure you set the input format to FullHTML for these fields when adding the markup!
Field1: (THIS MUST BE THE FIRST FIELD OF YOUR FORM!)
Name: Progress Bar Setup
Type: markup
Markup value:
<input id="progress_key" name="UPLOAD_IDENTIFIER" type="hidden" value="%username%server[REQUEST_TIME]" />Field2: (i put this before the submit button, but do whatever you like)
Name: Progress Bar
Type: markup
Markup value:
<span id="uploadprogressbar" class="progressbar" style="display: none;">0%</span>Download the JQuery progress bar plugin from: http://t.wits.sg/jquery-progress-bar/ extract it to your site and make sure the relevant bits are included in your template.
I then added the following script into the HEAD of my template:
Finally i had to edit /modules/webform/webform.module. I searched for "enctype" and found:
$form['#attributes']['enctype'] = 'multipart/form-data';Quickly added a second line to make it:
And that was that. The webform now displays an AJAX progress bar for file uploads. It doesnt seem to work in Chrome, but works elsewhere. Also Chrome shows the upload % in its status bar anyway so its no biggie!
Andy