Uploadify dynamic file extension
Tech-Today

Uploadify dynamic file extension


Requirement: To change the file extension depending on the value of a dropdown box.

The code will explain how this can be achieve.

<script type="text/javascript">
$(document).ready(function() {
var fileExt = "";
var fileDesc = "";
var leftSelected = $("#categories option:selected");
if(leftSelected.val() == "PRI") {
fileExt = "*.jpg;*.jpeg;*.gif;*.doc;*.docx;*.pdf";
fileDesc = "Allowed Files (.JPG, .JPEG, .GIF, .DOC, .DOCX, .PDF)";
} else if(leftSelected.val() == "AUD") {
fileExt = "*.mp3;*.wav";
fileDesc = "Allowed Files (.MP3, .WAV)";
} else if(leftSelected.val() == "VID") {
fileExt = "*.flv;*.mpg;*.mp4;*.avi";
fileDesc = "Allowed Files (.FLV, .MPG, .MP4, .AVI)";
} else if(leftSelected.val() == "SMS") {
fileExt = "*.html,*.htm,*.doc;*.docx;*.pdf";
fileDesc = "Allowed Files (.HTML, .HTM, .DOC, DOCX, PDF)";
}
$('#custom_file_upload').uploadify({
'uploader' : "uploadify.swf",
'script' : "uploadify.php",
'cancelImg' : "cancel.png",
'checkScript' : "uploadifycheck.php",
'folder' : "",
'pagePath' : "",
'multi' : true,
'auto' : false,
'fileExt' : fileExt,
'fileDesc' : fileDesc,
'queueID' : 'custom-queue',
'queueSizeLimit' : 5,
'displayData' : 'percentage',
'scriptData' : {'categories': $('#categories').val()}, //send a post variable in uploadify.php
'onSelectOnce' : function(event,data) {
$('#status-message').text(data.filesSelected + ' files have been added to the queue.');
},
'onAllComplete' : function(event,data) {
$('#status-message').text(data.filesUploaded + ' files uploaded, ' + data.errors + ' errors.');
location.reload();
}
});
</script>

Note: Need to link with jquery.js




- How To Upload A File In An Mvc3 C# Ajax Form
It's easy to upload file in a synchronous form, where you just post the file and read a HttpPostedFile variable in the server side: In plain html form, take note of the form enctype property: //the view (index.cshtml) @using (Html.BeginForm("Upload",...

- Jquery Document.ready $("#controlid") Is Null Error
I'm working on a script that uses jquery and it's working normally on a simple page that I made. However when I create a master page in c# and put the jquery code in the page that extends the master page I get this error: $("#controlId") is null...

- Uploadify Check Script Not Working
To setup uploadify see the previous post: Uploadify Setup To add a check script add the following config: $('#custom_file_upload').uploadify({ ... 'checkScript' : "uploadifycheck.php", } Where uploadifycheck should contain the lines:...

- How To Use Syntaxhighlighter V3.0.83 On Blogger
The previous version of syntaxhighlighter uses flash to render the code, but in this version they are only using javascript. Here's how I integrated syntaxhighlighter to this blogger blog. Sample Source Code <pre class="brush: java"> public...

- Integrate Uploadify With Codeigniter
Googling around I've found several solutions, but not to my liking some even suggest to edit the fla. Well there's no problem with that if you want to. The problem with the uploadify.swf is that if uploads the file relative to the .swf location....



Tech-Today








.