Basically what I’m trying to do is generate an alphanumeric string, which is passed to the php handler, as well as back to the upload form. When the upload is complete, the form then creates a link using the alphanumeric string.
I’ve gotten everything to work, except for one issue. There is only one random string that’s generated, so if you try to upload multiple files at the same time, every one of them has the same string name. I need them each to have different names, but I can’t seem to figure out how, while still being able to pass back to the form and the php.
Here’s my script:
<script>
function randomString(length, chars) {
var result = '';
for (var i = length; i > 0; --i) result += chars[Math.round(Math.random() * (chars.length - 1))];
return result;
}
var sessid = '';
var data = document.getElementById('data');
$(document).ready(function () {
$('#myModal').modal({
show: false
});
$('#mm').modal({
show: false
});
$(function () {
$('#file_upload').uploadify({
'fileObjName': 'file',
'fileSizeLimit': '8MB',
'buttonText': 'BROWSE FILE(S)...',
'fileTypeExts': '*.JPEG; *.GIF; *.PNG; *.APNG; *.TIFF; *.BMP; *.PDF; *.XCF',
'cancelImg': 'uploadify-cancel.png',
'swf': 'uploadify.swf',
'uploader': 'uploadify.php',
'formData': randomString(7, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'),
'auto': false
});
});
});
</script>
I also made a small modification to jquery.uploadify-3.1.min.js, which allowed for the random string to be passed back to the form.
if (c.inArray("onUploadSuccess", g.overrideEvents) < 0) {
c("#" + f.id).find(".data").html(" - " + this.settings.post_params);
}
If anyone wants to see it all in action, you can see it here: http://icap.me/test/files.php
Ignore the broken design, for now I’m just trying to get it to work.
Use an
onUploadStarthandler to set the random string used for the upload.