I'm making an upload website and I'm trying to add an upload progress bar. For some reason, the Ajax form I am using in my scripts is breaking the PHP code, therefore, stopping it from uploading.
When I remove the Ajax form, the Javascript runs fine and the PHP manages to upload the file, but with it in, it breaks. Any ideas? Much appreciated.
<input type="submit" name="sub" class="button" value="Submit" onclick="upload_image();">
<div class='progress' id="progress_div">
<div class='bar' id='bar1'></div>
<div class='percent' id='percent1'>0%</div>
</div>
<script>
function upload_image()
{
var bar = $('#bar');
var percent = $('#percent');
$('#myForm').ajaxForm({
beforeSubmit: function() {
document.getElementById("progress_div").style.display="block";
var percentVal = '0%';
bar.width(percentVal)
percent.html(percentVal);
},
uploadProgress: function(event, position, total, percentComplete) {
var percentVal = percentComplete + '%';
bar.width(percentVal)
percent.html(percentVal);
},
success: function() {
var percentVal = '100%';
bar.width(percentVal)
percent.html(percentVal);
},
});
}
</script>
I'm using:
if(isset($_POST['sub']))
for the PHP