Announcement

Collapse
No announcement yet.

Remote File Size

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Jez
    replied
    Originally posted by Max Albert
    ........and how is that any different?
    Umm...its VERY different. For a start it doesn't download all the file, only the header files directly from the server.

    I wanted to get the file size of very large files, thats why I prefer this method.

    Leave a comment:


  • Mark Hensler
    replied
    haha!
    I hope I didn't sound snotty or stuck up. I was trying to sound thoughtfull. I like to question things. I think you learn more that way.

    That's true. I overlooked that point.

    Leave a comment:


  • Vergil
    replied
    ALBERT HAS SPOKEN!
    *roaring thunder and lightning*

    In that case I would think it's impossible to get remote file size. Thats only if you are getting some sort of script or something. HTML, text, images, everything else should work fine.
    Last edited by Vergil; Sun 24 Jun '01, 8:42pm.

    Leave a comment:


  • Mark Hensler
    replied
    ........and how is that any different?

    BTW... both are inaccurate. Your getting the size of the output of the requested file. Not the actual size of the file. So if you try to get the size of a .php file, you'll get the size of what it print()s not the size of the script that print()ed it. Make sense?

    PHP Code:
    // 25 bytes of php
    // 11 bytes of printed content
    <? echo "Hello World"?>

    Leave a comment:


  • Jez
    replied
    But you have to download all the file. Heres what I finally came up with:

    PHP Code:
    function getRemoteSize($rURL) {
    $rHost ereg_replace("http://([^\/]+)/(.*)""\\1"$rURL);
    $rPath ereg_replace("http://([^\/]+)/(.*)""/\\2"$rURL);
    $fp fsockopen($rHost80, &$errno, &$errstr10);
    if (!
    $fp) {
      echo 
    "ERROR: $errno$errstr";
    } else {
      
    fputs($fp"HEAD $rPath HTTP/1.0\r\nHost: $rHost\r\nConnection: close\r\n\r\n");
      while (!
    feof($fp)) {
        
    $response .= fgets($fp128);
      }
    fclose($fp);
    }
    return 
    ereg_replace("(.*)(Content-Length: )([0-9]*)(.*)","\\3",$response);
    }

    echo 
    "File Size: ".getRemoteSize("http://www.php.net/"); 

    Leave a comment:


  • Mark Hensler
    replied
    Why stop there?
    PHP Code:
    print strlen(@implode(''file("http://www.cnunited.com/index.php"))); 
    or (3 characters shorter)
    PHP Code:
    print strlen(@join(''file("http://www.cnunited.com/index.php"))); 
    Muahahaha! Not even Santa Claus can save you now!

    Leave a comment:


  • dp 
    replied
    Re: this kinda works

    Originally posted by krs-one
    PHP Code:
    <?php

    $contents 
    file("http://www.cnunited.com/index.php");

    for(
    $i=0$i<count($contents); $i++)
        
    $string .= $contents[$i];

    print 
    strlen($string);

    ?>
    PHP Code:
    $string = @implode(''file("http://www.cnunited.com/index.php"));
    print 
    strlen($string); 
    even shorter

    Leave a comment:


  • krs-one
    replied
    this kinda works

    Jez:

    This script works somewhat, since you can not use the filesize() function on remote files.

    This script works best with just regular html and ASCII files, it does not give an accurate reading for binary files, like .zip files and such.

    PHP Code:
    <?php

    $contents 
    file("http://www.cnunited.com/index.php");

    for(
    $i=0$i<count($contents); $i++)
        
    $string .= $contents[$i];

    print 
    strlen($string);

    ?>
    Hope this helps.

    Leave a comment:


  • Jez
    started a topic Remote File Size

    Remote File Size

    Is there any way in PHP to determine the file size of a remote file?
widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
Working...
X