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;
}

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

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?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.