Results 1 to 10 of 10

Thread: [RESOLVED] How to get size of file in website

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Location
    United States
    Posts
    157

    Resolved [RESOLVED] How to get size of file in website

    Hello
    How can I get size of a file which website?
    Example:
    http://www.website/file.zip

    How can I get size of file.zip?

    Thx

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: How to get size of file in website


  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Location
    United States
    Posts
    157

    Re: How to get size of file in website

    filesize() doesn't work for files on websites.

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: How to get size of file in website

    Sorry, didn't read carefully enough.

    You can't get the size of files on remote websites. Not easily and reliably, anyway

  5. #5
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: How to get size of file in website

    If the response sends a Content-Length header then you can get the size. This is not necessarily the size of the file though, it is the size f the response body.

    If there is no Content-Length header, you'll need to download the entire file first.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Location
    United States
    Posts
    157

    Re: How to get size of file in website

    Quote Originally Posted by visualAd
    If the response sends a Content-Length header then you can get the size. This is not necessarily the size of the file though, it is the size f the response body.

    If there is no Content-Length header, you'll need to download the entire file first.
    How can I do it by using Content-Length?

  7. #7
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: How to get size of file in website

    i am going to work now. I will reply when I get back. If pena doesn't beat me to it.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Location
    United States
    Posts
    157

    Re: How to get size of file in website

    Quote Originally Posted by visualAd
    i am going to work now. I will reply when I get back. If pena doesn't beat me to it.
    Could you do it?
    Thanks

  9. #9
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: How to get size of file in website

    You can use the stream_get_meta_data() function to get the heads from an fopen wrapper.

    PHP Code:
          if (!($fp = @fopen($url'r'))) {
             
    /* error here - as url could not be opened */
          
    }

         
    $metaData stream_get_meta_data($fp);
         
    $size null;
         foreach (
    $metaData['wrapper_data'] as $header) {
             if (
    strpos(strtolower($header), 'content-length') !== false) {
                
    $size substr($headerstrpos($header':') + 1);
                break;
             }
          }

          if (
    is_null($size)) {
              
    /* Content-Length header not found */
          

    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Location
    United States
    Posts
    157

    Re: How to get size of file in website

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width