Jump to content

Progress bar for install game


laponac84

Recommended Posts

I try to upload fale(game.swf) from another webserver to my webserver, and that is not problem. Problem is create progress bar to track copying files process, or more precisely, the calculation and display the value in percentage, of file that i  currently copied from other webserver to my webserver (alredy have full size of file variable)
 
This is what i do for now.
-----------------------------------------------
 
after clik on install buton (div element)
 
jq.js file
$(".button").click(function () {
var val = $(this).attr("id"); //id have url value for game i want to install http://www......game.swf
$.post('proces.php',{val: val},function(data){
$(".final_data").html(data);
});   
});
proces.php file
$link = $_POST['val'];

// ...

function remotefileSize($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
curl_exec($ch);
$filesize = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
curl_close($ch);
if ($filesize) return $filesize;
}
$b =  remotefileSize($igrica_mochi);
$mb = $b / 1048576;
echo round($mb, 2). " Mb<br>"; //round(1.95583, 2);
echo $b. " bytes<br>";
// ...
if (@copy($game_from_other_server, $game_in_my_server) ) { echo "- Finish!<br>"; }else{ echo "- Error.<br>"; $errors= error_get_last(); echo "- COPY ERROR: ".$errors['type']; echo "<br />\n".$errors['message']; }

Formula for calculating procent is

progres = (current / full) * 100

And question is value of 'current'  :)
 

Any ideas ?
 
Link to comment
Share on other sites

post-136675-0-94945400-1386124270_thumb.pngThis is what I managed to do it, but not good enough.
I made a progress bar on the basis of completed processes. Problem occurs when the file (game) is large, and the progress bar is stationary for a long time until the whole game does not load on server. After that, script continue to load the rest of the process. For the user it is very important to have live information on what is currently happening. For these reasons, is really important to measure copy files from remote server to current server. (all processes other than copying files, are very short and quick, so it is not necessary to show them in progress bar becaose they ending in a split of second)

As you can see, I do not have a html form , (Every example I found on the Internet is "Upload form")  i have one xml file, which contains url of game. By clicking the install, I pick a game that I copied to current server from remote server. I get with the help jquery games file url, and sent (post) for processing in php file

Example

 

Part of index.php file

<div class="game">
<div style="float: none; margin: 5px ;" class="button" name="<?php echo $game['uuid']; ?>" id="url value">Install</div>
<div id="<?php echo $game['uuid']; ?>"> </div>
</div>
 
 
jqerry file:
$(".button").click(function () 

var value = $(this).attr("id");

$(this).hide();

$.post('process.php',{val: value},function(data){

$("#" + install).html(data); // collecting data

});

$.post('process2.php',{val: value},function(data){

$("#" + install).html(data); // copy main file

}); 

 // rest call for process file...

});
 
As you can see in my jquery file, I know the exact path of the file to be copied from the remote server ( ID of install div have that value)
 
Process1.php, Process2.php , and rest... are quite the same file, which in the end have a progress bar in percentage

How to make progress bar, with this data ?

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.