Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] pobieranie rozmiaru pliku zdalnego
fredzio90
post
Post #1





Grupa: Zarejestrowani
Postów: 251
Pomógł: 0
Dołączył: 19.02.2007

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


mam pewien problem, mianowicie chciałbym się dowiedzieć czy jest funkcja która po podaniu adresu np: http://forum.php.pl/style_images/1/logo4.gif zwracała mi rozmiar danego pliku (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif) potrzebne mi to jest przy pisaniu skryptu do ograniczania pobierania plików..

Ten post edytował fredzio90 6.03.2008, 23:42:28
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
fredzio90
post
Post #2





Grupa: Zarejestrowani
Postów: 251
Pomógł: 0
Dołączył: 19.02.2007

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


znalazłem i przepraszam za post, ale chciałbym się upewnić, jakie wymagania musi mieć serwer aby to działąło bo testuje ten skypt (funckję) na locaslhoscie na full opcjach...:

  1. <?php
  2. function get_remote_file_size($url, $readable = true){
  3.  $parsed = parse_url($url);
  4.  $host = $parsed["host"];
  5.  $fp = @fsockopen($host, 80, $errno, $errstr, 20);
  6.  if(!$fp) return false;
  7.  else {
  8.  @fputs($fp, "HEAD $url HTTP/1.1r\n");
  9.  @fputs($fp, "HOST: $hostr\n");
  10.  @fputs($fp, "Connection: closer\nr\n");
  11.  $headers = "";
  12.  while(!@feof($fp))$headers .= @fgets ($fp, 128);
  13.  }
  14.  @fclose ($fp);
  15.  $return = false;
  16.  $arr_headers = explode("\n", $headers);
  17.  foreach($arr_headers as $header) {
  18. // follow redirect
  19. $s = 'Location: ';
  20. if(substr(strtolower ($header), 0, strlen($s)) == strtolower($s)) {
  21. $url = trim(substr($header, strlen($s)));
  22. return get_remote_file_size($url, $readable);
  23. }
  24.  
  25. // parse for content length
  26.  $s = "Content-Length: ";
  27.  if(substr(strtolower ($header), 0, strlen($s)) == strtolower($s)) {
  28.  $return = trim(substr($header, strlen($s)));
  29.  break;
  30.  }
  31.  }
  32.  if($return && $readable) {
  33. $size = round($return / 1024, 2);
  34. $sz = "KB"; // Size In KB
  35. if ($size > 1024) {
  36. $size = round($size / 1024, 2);
  37. $sz = "MB"; // Size in MB
  38. }
  39. $return = "$size $sz";
  40.  }
  41.  return $return;
  42. }
  43. ?>


Ten post edytował fredzio90 6.03.2008, 23:56:00
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: 15.10.2025 - 05:51