i want to add a progress bar to my upload code so i've installed uploadprogress extension ( actually i've downgraded my wamp server to wamp 2.0 as this one already has the extension but new versions seems to have problem with it )
here is my backend code
/////////////////// uploading
<?php
if (isset($_POST['upload'])) {
echo 'UPLOADING . . . <br />';
$location = './uploads';
$new= uniqid().'.'.end(explode('.' , basename($_FILES['mailfile']['name']) ));
if(move_uploaded_file( $_FILES['mailfile']['tmp_name'],"$location/$new"))
echo 'DONE !! ';
else
echo 'error';
}
/////////////// getting upload info
else if(isset($_GET['get_info']))
{
if (function_exists("uploadprogress_get_info")) {
$info = uploadprogress_get_info($_GET['get_info']);
} else {
$info = 'nofunc';
}
var_dump($info);
}
/////////////// upload form
else
{ $uploadID = substr(md5(microtime(true)), 0, 10);
?>
<form enctype="multipart/form-data" action="uploadprogress.php" method="post" >
<input type="text" name="UPLOAD_IDENTIFIER" value="<?php echo $uploadID; ?>" id="uploadIdentifier" />
<input id="file" name="mailfile" type="file" />
<input type="submit" value="Send File" id="btn" name="upload" />
</form>
<?php
}
and this is my front html/jquery code when file is being uploaded it gets the UPLOAD_IDENTIFIER value from iframe and the sends it to the set() function which is suppose to get the upload progress via ajax calls but it always returns null
<html>
<head>
<script language="javascript" src="../../js/jquery.js"></script>
<script>
var val;
$(function(){
$('#progress_iframe').load(function() {
var ifr = $(this);
$(this)
.contents()
.find('#btn')
.bind('click', function() {
val = ifr.contents().find('#uploadIdentifier').val();
set();
// do stuff
});
});
})
function set() {
$.get('uploadprogress.php' , {get_info : val} , function(data){
data = $.trim(data);
$('#info').html(data) ;
if(data < 100 )
set();
})
}
</script>
</head>
<body>
<div>
<iframe id="progress_iframe" src="uploadprogress.php" frameborder="0"> </iframe>
<span id="info"></span>
</div>
</body>
</html>
so the file is being uploaded without any problem and i've tried a big file but still as the file was being uploaded the uploadprogress_get_info was null