简体   繁体   中英

Downloading using wget in php

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM