refiking Posted November 10, 2009 Share Posted November 10, 2009 I am trying to get the filesize of a file on another server. Do I have to log into the account via ftp_connect to get this? Please help. echo filesize($file); Link to comment https://forums.phpfreaks.com/topic/181008-filesize-function-help-needed/ Share on other sites More sharing options...
Adam Posted November 10, 2009 Share Posted November 10, 2009 If it's listed here shouldn't be a problem: http://uk2.php.net/manual/en/wrappers.php Are you getting an error? Link to comment https://forums.phpfreaks.com/topic/181008-filesize-function-help-needed/#findComment-954988 Share on other sites More sharing options...
refiking Posted November 10, 2009 Author Share Posted November 10, 2009 yeah, I had no problem with fopen, but it's still not displaying the filesize when I wrote filesize($file) Link to comment https://forums.phpfreaks.com/topic/181008-filesize-function-help-needed/#findComment-954991 Share on other sites More sharing options...
darkvengance Posted November 10, 2009 Share Posted November 10, 2009 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. Link to comment https://forums.phpfreaks.com/topic/181008-filesize-function-help-needed/#findComment-954992 Share on other sites More sharing options...
mattal999 Posted November 10, 2009 Share Posted November 10, 2009 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 https://forums.phpfreaks.com/topic/181008-filesize-function-help-needed/#findComment-954995 Share on other sites More sharing options...
refiking Posted November 10, 2009 Author Share Posted November 10, 2009 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 https://forums.phpfreaks.com/topic/181008-filesize-function-help-needed/#findComment-954998 Share on other sites More sharing options...
refiking Posted November 10, 2009 Author Share Posted November 10, 2009 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 https://forums.phpfreaks.com/topic/181008-filesize-function-help-needed/#findComment-954999 Share on other sites More sharing options...
mattal999 Posted November 10, 2009 Share Posted November 10, 2009 Strange. That function works fine for me. Are you on shared hosting? Can be something in the php.ini that's blocking it. Link to comment https://forums.phpfreaks.com/topic/181008-filesize-function-help-needed/#findComment-955001 Share on other sites More sharing options...
refiking Posted November 10, 2009 Author Share Posted November 10, 2009 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. Link to comment https://forums.phpfreaks.com/topic/181008-filesize-function-help-needed/#findComment-955002 Share on other sites More sharing options...
mattal999 Posted November 10, 2009 Share Posted November 10, 2009 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 https://forums.phpfreaks.com/topic/181008-filesize-function-help-needed/#findComment-955004 Share on other sites More sharing options...
PFMaBiSmAd Posted November 10, 2009 Share Posted November 10, 2009 filesize() does not work for HTTP/HTTPS. It does work for FTP. get_headers() is php5 only. What php version are you using? Link to comment https://forums.phpfreaks.com/topic/181008-filesize-function-help-needed/#findComment-955017 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.