Statusbalken in PHP

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Quick & Dirty - Nur als Beispiel gedacht!

    Quellcode

    1. <?php
    2. $maxwidth = 200;
    3. $maxusers = 75;
    4. $onlineusers = 70;
    5. $percent = 100 / $maxusers * $onlineusers;
    6. $loadwidth = $maxwidth - ($percent / 100) * $maxwidth;
    7. $buffer = "
    8. <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
    9. <html>
    10. <head>
    11. <meta http-equiv=\"content-type\" content=\"text/html; charset=ISO-8859-1\">
    12. <title>Speicherplatzbelegung</title>
    13. <style type=\"text/css\">
    14. .speicher {
    15. background-color: green;
    16. width: ".$maxwidth."px;
    17. height: 15px;
    18. overflow: hidden;
    19. padding: 0;
    20. }
    21. .balken {
    22. top: 0;
    23. width: ".$maxwidth."px;
    24. height: 15px;
    25. background-color: red;
    26. }
    27. </style>
    28. </head>
    29. <body>
    30. $onlineusers von $maxusers online!
    31. <div class=\"speicher\">
    32. <div class=\"balken\" style=\"position: relative; left: -".$loadwidth."px;\"></div>
    33. </div>
    34. </body>
    35. </html>";
    36. echo $buffer;
    37. ?>
    Alles anzeigen
  • Das geht wunderbar mit PHP, einzige Einschränkung: der Balken wird nur aktualisiert wenn die Seite neu geladen wird. Möchtest du das dynamisch immer machen brauchste wohl JavaScript.
    Ich würde es mit PHP und GD machen und den Statusbalken als Grafik einbinden. GD ist eigentlich immer mit installiert.
    ~ mfg SeBa

    Ich beantworte keine PMs zu Computer-/Programmierproblemen. Bitte wendet euch an das entsprechende Forum.

    [Blockierte Grafik: http://i.creativecommons.org/l/by-sa/3.0/80x15.png]
  • Also wenn Du eine Prozentuale Berechnung hast, dann hilft Dir vielleicht das weiter:

    [phpdoc]imagefilledrectangle[/phpdoc]

    Das nehme ich auch her. Mein Code:

    ratingbar.php

    Quellcode

    1. <?php
    2. // copied from the PHP manual:
    3. // http://us3.php.net/manual/en/function.imagefilledrectangle.php
    4. //this needs to reside in its own php page
    5. //you can include that php page in your html as you would an image:
    6. //<IMG SRC="makebar.php?rating=25.2&width=200&height=20" border="0">
    7. // rating is a percentage from 0 to 100.
    8. function drawRating($rating) {
    9. $width = $_GET['width'];
    10. $height = $_GET['height'];
    11. if ($width == 0) {
    12. $width = 300;
    13. }
    14. if ($height == 0) {
    15. $height = 15;
    16. }
    17. $rating = $_GET['rating'];
    18. $ratingbar = (($rating/100)*$width)-2;
    19. $image = imagecreate($width,$height);
    20. //colors
    21. $fill = ImageColorAllocate($image,0,255,0); //grün
    22. if ($rating > 49) { $fill = ImageColorAllocate($image,255,255,0); } //gelb
    23. if ($rating > 74) { $fill = ImageColorAllocate($image,255,128,0); } //orange
    24. if ($rating > 89) { $fill = ImageColorAllocate($image,255,0,0); } //rot
    25. $back = ImageColorAllocate($image,255,255,255);
    26. $border = ImageColorAllocate($image,0,0,0);
    27. ImageFilledRectangle($image,0,0,$width-1,$height-1,$back);
    28. ImageFilledRectangle($image,1,1,$ratingbar,$height-1,$fill);
    29. ImageRectangle($image,0,0,$width-1,$height-1,$border);
    30. imagePNG($image);
    31. imagedestroy($image);
    32. }
    33. Header("Content-type: image/png");
    34. drawRating($rating);
    35. ?>
    Alles anzeigen


    Und so lasse ich mir z. B. meinen freien Festplattenplatz anzeigen:

    Quellcode

    1. <?
    2. function ZahlenFormatieren($Wert)
    3. {
    4. if($Wert > 1099511627776)
    5. {
    6. $Wert = number_format($Wert/1099511627776, 2, ",", ".")." TB";
    7. }
    8. elseif($Wert > 1073741824)
    9. {
    10. $Wert = number_format($Wert/1073741824, 2, ",", ".")." GB";
    11. }
    12. elseif($Wert > 1048576)
    13. {
    14. $Wert = number_format($Wert/1048576, 2, ",", ".")." MB";
    15. }
    16. elseif($Wert > 1024)
    17. {
    18. $Wert = number_format($Wert/1024, 2, ",", ".")." kB";
    19. }
    20. else
    21. {
    22. $Wert = number_format($Wert, 2, ",", ".")." Bytes";
    23. }
    24. return $Wert;
    25. }
    26. $frei = disk_free_space("./");
    27. $insgesamt = disk_total_space("./");
    28. $belegt = $insgesamt-$frei;
    29. $prozent_belegt = 100*$belegt/$insgesamt;
    30. ?>
    31. </td><td>
    32. <table width=340 border=0 cellspacing=1 cellpadding=3 bgcolor=#C0C0C0>
    33. <tr><td bgcolor=#F4F4F4><? echo $lang[diskspace];?></td><td bgcolor=#F4F4F4><?=ZahlenFormatieren($insgesamt);?></td></tr>
    34. <tr><td bgcolor=#F4F4F4><? echo $lang[in_use];?></td><td bgcolor=#F4F4F4><?=ZahlenFormatieren($belegt);?> (<?=round($prozent_belegt,"2");?> %)</td></tr>
    35. <tr><td colspan=2 bgcolor=#F4F4F4 align=center><center><img src="ratingbar.php?rating=<?=round($prozent_belegt,"2");?>" border="0"></td></tr>
    36. <tr><td bgcolor=#F4F4F4><? echo $lang[free];?></td><td bgcolor=#F4F4F4><?=ZahlenFormatieren($frei);?>
    37. </td></tr></table>
    Alles anzeigen


    Gruß Inekai
    "Die Wahrheit wird oft verdunkelt, aber sie erlischt nie."

    Livius