Porl123 Posted May 16, 2009 Share Posted May 16, 2009 is there a function that can do this for a URL rather than a path as it's an external image link i'm trying to validate to check that exceedingly large files aren't being set as users avatar images. thanks! Link to comment https://forums.phpfreaks.com/topic/158396-solved-reading-filesize-of-a-file/ Share on other sites More sharing options...
wildteen88 Posted May 16, 2009 Share Posted May 16, 2009 Use getimagesize maybe Link to comment https://forums.phpfreaks.com/topic/158396-solved-reading-filesize-of-a-file/#findComment-835338 Share on other sites More sharing options...
Porl123 Posted May 16, 2009 Author Share Posted May 16, 2009 Yeah I thought that too but it only gives the height and width rather than the pixels, so if a user adds an animated gif it still pretty much bones the page with lag Link to comment https://forums.phpfreaks.com/topic/158396-solved-reading-filesize-of-a-file/#findComment-835339 Share on other sites More sharing options...
Porl123 Posted May 16, 2009 Author Share Posted May 16, 2009 sorry not pixels, bytes* Link to comment https://forums.phpfreaks.com/topic/158396-solved-reading-filesize-of-a-file/#findComment-835340 Share on other sites More sharing options...
wildteen88 Posted May 16, 2009 Share Posted May 16, 2009 Oh shoot. Forgot about that. There is not built in function for getting the file size remote files (only local files). However I found this custom function http://www.phpcentral.com/207-get-filesize-remote-file.html Link to comment https://forums.phpfreaks.com/topic/158396-solved-reading-filesize-of-a-file/#findComment-835347 Share on other sites More sharing options...
thebadbad Posted May 16, 2009 Share Posted May 16, 2009 I would use this: <?php $url = 'URL here'; $headers = get_headers($url, 1); $filesize = $headers['Content-Length']; ?> Requires PHP 5. Else file_get_contents() can be used: <?php $url = 'URL here'; $filesize = strlen(file_get_contents($url)); ?> Link to comment https://forums.phpfreaks.com/topic/158396-solved-reading-filesize-of-a-file/#findComment-835348 Share on other sites More sharing options...
Porl123 Posted May 16, 2009 Author Share Posted May 16, 2009 Both methods work great! thanks for all the help guys Link to comment https://forums.phpfreaks.com/topic/158396-solved-reading-filesize-of-a-file/#findComment-835350 Share on other sites More sharing options...
thebadbad Posted May 16, 2009 Share Posted May 16, 2009 For your information, my former method is approximately twice as fast as the latter. Disregard that, they take the same time to execute. My mistake Link to comment https://forums.phpfreaks.com/topic/158396-solved-reading-filesize-of-a-file/#findComment-835354 Share on other sites More sharing options...
.josh Posted May 16, 2009 Share Posted May 16, 2009 except that headers can be faked. Link to comment https://forums.phpfreaks.com/topic/158396-solved-reading-filesize-of-a-file/#findComment-835359 Share on other sites More sharing options...
thebadbad Posted May 16, 2009 Share Posted May 16, 2009 except that headers can be faked. Yeah, that's right. And in this scenario it's important to be sure, so don't use the header method. Link to comment https://forums.phpfreaks.com/topic/158396-solved-reading-filesize-of-a-file/#findComment-835363 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.