Jump to content

Filesize function help needed


refiking

Recommended Posts

If it isnt working, try this function. It's served me well.

 

function getFileSize($url) {
    if (substr($url, 0, 4)=='http') {
        $x = array_change_key_case(get_headers($url, 1), CASE_LOWER);
        if (strcasecmp($x[0], 'HTTP/1.1 200 OK') != 0 ) {
            $x = $x['content-length'][1];
        } else {
            $x = $x['content-length'];
        }
    } else {
        $x = @filesize($url);
    }
    return $x;
}

Link to comment
Share on other sites

hmm..you shouldn't have to login...for example this right here should work:

 

echo filesize("http://www.phpfreaks.com/forums/index.php");

 

But then again I'm not 100% sure on that, just try it out and see.

 

Here's what that returned:

 

Warning: filesize() [function.filesize]: stat failed for http://www.phpfreaks.com/forums/index.php in XXX on line 4

Link to comment
Share on other sites

If it isnt working, try this function. It's served me well.

 

function getFileSize($url) {
    if (substr($url, 0, 4)=='http') {
        $x = array_change_key_case(get_headers($url, 1), CASE_LOWER);
        if (strcasecmp($x[0], 'HTTP/1.1 200 OK') != 0 ) {
            $x = $x['content-length'][1];
        } else {
            $x = $x['content-length'];
        }
    } else {
        $x = @filesize($url);
    }
    return $x;
}

 

I entered getFileSize("http://www.phpfreaks.com/forums/index.php"); and it didn't return anything.  Did I not use it correctly?

Link to comment
Share on other sites

Does the file I am trying to recover the size of have to be on the same server?  Once again, that's what I think the issue might be. 

 

I don't think so, because the way I use that function is to grab the size of external files on many different websites, and it returns the correct value.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.