Reputation: 3721
I am using wget in php script to download images from the url submitted by the user. Is there some way for me to determine the size of image before actually downloading it and restricting the size of download to 1mb? Also can I possibly check that the url points to an image only and not an entire website without downloading?
I dont want to end up filling my server with malware.
Upvotes: 0
Views: 976
Reputation: 656
Before loading you can check headers (you'll have to download them though). I use curl - not wget. Here's an example:
$ curl --head http://img.yandex.net/i/www/logo.png HTTP/1.1 200 OK Server: nginx Date: Sat, 16 Jun 2012 09:46:36 GMT Content-Type: image/png Content-Length: 3729 Last-Modified: Mon, 26 Apr 2010 08:00:35 GMT Connection: keep-alive Expires: Thu, 31 Dec 2037 23:55:55 GMT Cache-Control: max-age=315360000 Accept-Ranges: bytes
Content-Type and Content-Length should normally indicate that the image is ok
Upvotes: 2