Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Policzenie rozmiaru pliku
Destrudo
post
Post #1





Grupa: Zarejestrowani
Postów: 74
Pomógł: 0
Dołączył: 10.10.2011

Ostrzeżenie: (0%)
-----


Hej,

Mam taki problem, mianowicie: chciałbym listować pliki css z danej strony i liczyć ich rozmiar. Listowanie udało się zrobić poniższym kodem:
  1. <?php
  2.  
  3. $url="wp.pl";
  4. $file = file_get_contents('http://'.$url);
  5. $doc = new DOMDocument();
  6. $doc->loadHTML($file);
  7. $domcss = $doc->getElementsByTagName('link');
  8. $sum=0;
  9. foreach($domcss as $links) {
  10. if( strtolower($links->getAttribute('rel')) == "stylesheet" ) {
  11. $tre = "". $links->getAttribute('href') ."<br />";
  12. echo $tre;
  13. }
  14. }
  15.  
  16. ?>

jednak za nic nie mogę zrobić poprawnego wyliczenia rozmiaru w kb. Myslałem o liczeniu znaków (to byłyby bajty), ale też nie chce poprawnie mi to zadziałać. Macie może jakiś pomysł?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
chomikiki
post
Post #2





Grupa: Zarejestrowani
Postów: 14
Pomógł: 1
Dołączył: 16.09.2016
Skąd: Wrocław

Ostrzeżenie: (0%)
-----


  1. function remote_file_size($url){
  2. # Get all header information
  3. $data = get_headers($url, true);
  4. # Look up validity
  5. if (isset($data['Content-Length'])){
  6. # Return file size
  7. return (int) $data['Content-Length'];
  8. }
  9. }
  10.  
  11. $url='wp.pl';
  12. $file = file_get_contents('http://'.$url);
  13. $doc = new DOMDocument();
  14. $doc->loadHTML($file);
  15. $domcss = $doc->getElementsByTagName('link');
  16. $sum=0;
  17.  
  18. foreach($domcss as $links) {
  19. if($links->getAttribute('rel') == "stylesheet") {
  20. echo $links->getAttribute('rel').' ';
  21. $tre=$links->getAttribute('href');
  22. echo $tre.'<br>';
  23. $sum+=remote_file_size($tre);
  24. }
  25. }
  26. echo 'suma dla '.$url.' -> '.$sum;
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 9.10.2025 - 18:14