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); Quote Link to comment 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? Quote Link to comment 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) Quote Link to comment 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. Quote Link to comment 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; } Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.