Jump to content

Realtime Copying


Loldongs

Recommended Posts

Hey guys,

 

In some webapplications when you are installing say a voice/gameserver it has a realtime/live percentage bar how would i go about making one of these

 

<?php

    shell_exec("cp -Rf skel/css/* /home/dean/port/*");

?>

 

How can i get the percentage that the current copy has done are there any premade classes or library's for this

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/134257-realtime-copying/
Share on other sites

I have got it working some what

 

<style type="text/css">

body {
	font-family: Arial;
}

#percentbox {
	width: 300px;
	height: 20px;
	border: 1px solid #936;
}

#progress {
	text-align: center;
	font-family: Arial;
	background: #0F6;
	width: 100%;
	height: 100%;
}

</style>

<script type="text/javascript">

var total = 26906;

function updatePerc(p,up) {

	document.getElementById('files').innerHTML = up+' / '+total;

	document.getElementById('progress').style.width = p+'%';
	document.getElementById('progress').innerHTML = p+'%';
}

</script>


<div id="percentbox">

<div id="progress">
    	0%
    </div>
    <span id="files">0 / 26906</span> files copied

</div>

<?php

if(!($ssh = ssh2_connect('127.0.0.1', 22))){
	die("Connection Error");
}

if(!ssh2_auth_password($ssh, 'root', '***')) {
	die("Username and Password wrong");
}    

$stream = ssh2_exec($ssh, 'cp -Rfv /home/vgame/skel/css /home/vgame/skel/test');

stream_set_blocking( $stream, true );

$data = "";
$nf = 26906;

$i = 0;

$q = false;

    while( $buf = fread($stream,4096) ){
	$lines = explode("\n",$buf);
	$i = $i + count($lines);

	# need this so it flushes
	echo '<p style="display: none;">'.$buf.'</p>';

	$pe = round($i/26906*100,2);
	echo '<script type="text/javascript">updatePerc("'. $pe .'",'. $i .');</script>';

	flush();
}
            
fclose($stream);
?>

 

Just incase someone wants it

Link to comment
https://forums.phpfreaks.com/topic/134257-realtime-copying/#findComment-699146
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.