shukra Posted June 10, 2008 Share Posted June 10, 2008 Hi can anybody help me? pls, I want to get the file size of a url for example http://www.eatinguide.com/index.htm //my sample code like this //---------------------------------------------------------------- $site = file_get_contents('http://www.eatinguide.com/index.htm'); print "filesize[" . strlen($site)/1024 . "kb]"; //---------------------------------------------------------------- the problem is, it only display the size of text. how to display the whole size of the url? or website, including the image files? pls pls, help me? is it possible in PHP or should i have to write some scripts in pearl/cgi? thanks in advance! shukra Quote Link to comment https://forums.phpfreaks.com/topic/109521-get-file-size-of-website-or-url/ Share on other sites More sharing options...
David Nelson Posted June 10, 2008 Share Posted June 10, 2008 file_get_contents only gets text. If you use fopen() you will get images, etc... But, beware of bandwidth hogger. Quote Link to comment https://forums.phpfreaks.com/topic/109521-get-file-size-of-website-or-url/#findComment-561779 Share on other sites More sharing options...
hansford Posted June 10, 2008 Share Posted June 10, 2008 only one pls will do, otherwise we think you're a pu**y and nobody want to help those. Quote Link to comment https://forums.phpfreaks.com/topic/109521-get-file-size-of-website-or-url/#findComment-561821 Share on other sites More sharing options...
shukra Posted June 10, 2008 Author Share Posted June 10, 2008 only one pls will do, otherwise we think you're a pu**y and nobody want to help those. ok. what is your solution then? Quote Link to comment https://forums.phpfreaks.com/topic/109521-get-file-size-of-website-or-url/#findComment-561828 Share on other sites More sharing options...
FlyingIsFun1217 Posted June 10, 2008 Share Posted June 10, 2008 only one pls will do, otherwise we think you're a pu**y and nobody want to help those. Calm down, he was only asking a question... FlyingIsFun1217 Quote Link to comment https://forums.phpfreaks.com/topic/109521-get-file-size-of-website-or-url/#findComment-561991 Share on other sites More sharing options...
discomatt Posted June 10, 2008 Share Posted June 10, 2008 You'd have to use regex to parse the code looking for img tags, grab the URL in them, load them all using file_get_contents, check the size in the same way you're doing above (using the FILE_BINARY flag) Also, interesting note on the filesize() page Tip As of PHP 5.0.0, this function can also be used with some URL wrappers. Refer to List of Supported Protocols/Wrappers for a listing of which wrappers support stat() family of functionality. http://php.net/manual/en/function.filesize.php Quote Link to comment https://forums.phpfreaks.com/topic/109521-get-file-size-of-website-or-url/#findComment-562078 Share on other sites More sharing options...
Orio Posted June 10, 2008 Share Posted June 10, 2008 You'd have to use regex to parse the code looking for img tags, grab the URL in them, load them all using file_get_contents, check the size in the same way you're doing above (using the FILE_BINARY flag) Theoretically, this should work. But there's so many things that must be taken in consideration that makes it too hard to do. Example- a HTML page can contain iframes. Each iframe has to be parsed by itself. Except that, things like background images (that can be found only in the CSS file most of the times), background audio, flash objects, applets (and the list goes on) all have to be checked for their sizes. So bottom line, I don't think PHP is the language for this kind of project. I think the way to go here is launching a web browser and pointing it to the wanted address, and then to check how many bytes were downloaded. Of course it's not as that simple, but that's the base of the way I would use if I had to solve this problem. Orio. Quote Link to comment https://forums.phpfreaks.com/topic/109521-get-file-size-of-website-or-url/#findComment-562127 Share on other sites More sharing options...
discomatt Posted June 10, 2008 Share Posted June 10, 2008 Getting an exact size every time would be near impossible with php, but you could get a fairly close guess with a few simple checks... Look for included files (shtml, css, js) Parse all files for common image extensions and extract them (jpg, gif, png) Parse remaining tags/attribs (img, background ect) for anything that may have been missed Loop through extracted files and get sizes. Wouldn't take too long to code, assuming you know your regex. It would be horribly inefficient, and I would never recommend doing it on the fly (caching results?). Your way would be quite a bit more accurate, however. Quote Link to comment https://forums.phpfreaks.com/topic/109521-get-file-size-of-website-or-url/#findComment-562141 Share on other sites More sharing options...
Orio Posted June 10, 2008 Share Posted June 10, 2008 Getting an exact size every time would be near impossible with php, but you could get a fairly close guess with a few simple checks... Look for included files (shtml, css, js) Parse all files for common image extensions and extract them (jpg, gif, png) Parse remaining tags/attribs (img, background ect) for anything that may have been missed Loop through extracted files and get sizes. Wouldn't take too long to code, assuming you know your regex. It would be horribly inefficient, and I would never recommend doing it on the fly (caching results?). Your way would be quite a bit more accurate, however. That wouldn't be enough. The page could contain frames/iframes, each should be checked for everything. Flash and applets should be checked too. Some images could show up a lot of times, but they should be counted only once. And I am sure I missed a lot of things that should be checked too. This is not built for PHP, although it's not impossible. Orio. Quote Link to comment https://forums.phpfreaks.com/topic/109521-get-file-size-of-website-or-url/#findComment-562148 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.