从不信任的远程图像生成缩略图

时间:2014-05-28 22:37:18

标签: php curl thumbnails

我正在做一个简单的缩略图生成器,生成缩略图没问题,我使用PHP,file_get_contents来获取删除图像内容。

我想知道下载这样的文件内容是否存在安全问题(使用cURL或file_get_contents)。

  1. 如何限制文件大小并停止下载X​​ Mo?
  2. 如何查看二进制内容没有危险代码?
  3. 也许有另一种技术比PHP符合我的需要?
  4. 由于

1 个答案:

答案 0 :(得分:0)

这是我要测试的一段代码:

curl_setopt($cURL_Handle, CURLOPT_BUFFERSIZE, 128);
curl_setopt($cURL_Handle, CURLOPT_NOPROGRESS, false);
curl_setopt($cURL_Handle, CURLOPT_PROGRESSFUNCTION, function(
    $DownloadSize, $Downloaded, $UploadSize, $Uploaded) {
    // If $Downloaded exceeds 1KB, returning non-0 breaks the connection!
   return ($Downloaded > (1 * 1024)) ? 1 : 0;
});
curl_setopt($cURL_Handle, CURLOPT_WRITEFUNCTION, function(
    $ch, $str) {
    // Grab the first bytes, check if match a image "header signature"
});