简体   繁体   English

在php中使用wget下载

[英]Downloading using wget in php

I am using wget in php script to download images from the url submitted by the user. 我在php脚本中使用wget从用户提交的url下载图像。 Is there some way for me to determine the size of image before actually downloading it and restricting the size of download to 1mb? 有没有办法让我在实际下载之前确定图像大小并将下载大小限制为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. 我用curl - 而不是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 Content-Type和Content-Length通常应指示图像正常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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