PHP Ordner kopieren, PHP Progress Bar.
progress_bar.php |
||
<?php foreach($_GET as $x => $y){ $$x = trim($y); } include("cpb.class.php"); // Quelle Pfad ändern $source = "./inet"; // Ziel Pfad ändern $suchpfad = "./ziel"; $_SESSION['i'] = 0; $_SESSION['percent'] = 0; $color = '#7640EC'; $breite = 500; $hoehe = 50; if(!isset($sm)){ $cpb = new copy_progress_bar; $result = $cpb -> count_file($source); $sum1 = $result['directory']; $sum2 = $result['file']; $sm = round((($sum1 + $sum2) / 100),2); header("Location: ".$_SERVER["PHP_SELF"]."?sm=$sm"); }else{ echo '<table align="center" border="0" cellpadding="2" cellspacing="2" style="margin-top:200px;border:1px solid #efefef;">'; echo '<tr><td style="text-align:center;"> '; echo '<div id="progress" style="width:'.$breite.'px;line-height:'.$hoehe.'px;height:'.$hoehe.'px;border:1px solid #ccc;"></div>'; echo '</td></tr></table>'; $cpb = new copy_progress_bar; $cpb -> resource_copy($source,$suchpfad,$sm,$color,$hoehe); if(isset($_SESSION['i'])){unset($_SESSION['i']);} if(isset($_SESSION['percent'])){unset($_SESSION['percent']);} } ?> |
||
cpb.class.php |
||
<?php class copy_progress_bar{ public function count_file($src){ if(is_dir($src)){ $objekt['directory']=0; $objekt['file']=0; chdir($src); $this->handle = opendir("."); while($file=readdir($this->handle)){ if(is_dir($file) && $file!="." && $file!=".."){ $objekt['directory']++; $cpb = new copy_progress_bar; $y = $cpb -> count_file($file); $objekt['directory']+=$y['directory']; $objekt['file']+=$y['file']; } if(is_file($file)){ $objekt['file']++; } } if($src!=".") chdir("../"); closedir($this->handle); } return $objekt; } public function resource_copy($src,$pfd,$sm,$c,$h){ $i = 0; $this->ord = opendir($src); if(is_dir($pfd) == 0){ @mkdir($pfd); chmod($pfd, 0757); } while(false !== ($file = readdir($this->ord))){ if(($file != '.') && ($file != '..')){ if(is_dir($src . '/' . $file)){ $cpb = new copy_progress_bar; $cpb -> resource_copy($src . '/' . $file,$pfd . '/' . $file,$sm,$c,$h); $i++; $prc = intval(ceil($_SESSION['i']/$sm)); if($prc > 100){$prc = 100;} $percent = $prc."%"; if($_SESSION['percent'] != $percent){ $percent_w = ceil(($prc * 10) / 2); echo '<script language="javascript"> document.getElementById("progress").innerHTML= "<div style=\"text-align:center;width:'.$percent_w.';height:'.$h.'px;background-color:'.$c.';\">'.$percent.'</div>"; </script>'; echo str_repeat(' ',1024*64); flush(); $_SESSION['percent'] = $percent; } }else{ copy($src . '/' . $file,$pfd . '/' . $file); $i++; $prc = intval(ceil($_SESSION['i']/$sm)); if($prc > 100){$prc = 100;} $percent = $prc."%"; if($_SESSION['percent'] != $percent){ $percent_w = ceil(($prc * 10) / 2); echo '<script language="javascript"> document.getElementById("progress").innerHTML= "<div style=\"text-align:center;width:'.$percent_w.';height:'.$h.'px;background-color:'.$c.';\">'.$percent.'</div>"; </script>'; echo str_repeat(' ',1024*64); flush(); $_SESSION['percent'] = $percent; } } } } $_SESSION['i'] = $_SESSION['i'] + $i; $prc = intval(ceil($_SESSION['i']/$sm)); if($prc > 100){$prc = 100;} $percent = $prc."%"; if($_SESSION['percent'] != $percent){ $percent_w = ceil(($prc * 10) / 2); echo '<script language="javascript"> document.getElementById("progress").innerHTML= "<div style=\"text-align:center;width:'.$percent_w.';height:'.$h.'px;background-color:'.$c.';\">'.$percent.'</div>"; </script>'; echo str_repeat(' ',1024*64); flush(); $_SESSION['percent'] = $percent; } closedir($this->ord); } } ?> |
||