I have the following code which is supposed to return a random string back to the form once a file is uploaded. Previously to adding the onUploadSuccess code, it was working OK, but if I tried to upload multiple files, each file would have the same ID. I fixed this using the PHP to generate the random ID, but now I’m having issues getting the form to update.
The ID I’m trying to update is “data”, but when I upload the files, I get a Uncaught TypeError: Object [object Object] has no method 'call' error.
If someone could point me in the right direction, it would be appreciated. If you need more info, let me know.
The Javascript:
<script>
var sessid = '';
$(document).ready(function() {
$('#myModal').modal({show: false});
$('#mm').modal({show: false});
$('#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',
'auto': false,
'onUploadSuccess': $("data").livequery(function(file, data, response){
document.getElementById("data").innerHTML=data;
})
});
});
</script>
The PHP:
<?php
if ( is_uploaded_file( $_FILES['file']['tmp_name'])) {
$tempFile = $_FILES['file']['tmp_name'];
$fileParts = pathinfo($_FILES['file']['name']);
$randName = substr(sha1_file($_FILES['file']['tmp_name']), rand(0,30), 7);
$targetFile = 'uploads/'.$randName.'.' . $fileParts['extension'];
move_uploaded_file($tempFile,$targetFile);
echo $randName;
} else {
echo 'Malformed data';
}
?>
I think that your problem is that you need to supply the function definition to the “onUploadSuccess” option; get rid of the $(“data”).livequery( ).
Use: