PHP中通过CURL获取图片大小

use*_*807 5 php curl

我正在使用此代码在 php 中获取图像大小,它非常适合我。

$img = get_headers("http://ultoo.com/img_single.php", 1);
$size = $img["Content-Length"];
echo $size;
Run Code Online (Sandbox Code Playgroud)

但是如何通过 CURL 获得它?我试过这个,但不起作用。

$url = 'http://ultoo.com/img_single.php';
$ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, $url);
 curl_setopt($ch, CURLOPT_HEADER, 1);
 curl_setopt($ch, CURLOPT_HTTPHEADER, "Content-Length" );
 //curl_setopt($ch, CURLOPT_NOBODY, 1);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 $result = curl_exec($ch);

 $filesize = $result["Content-Length"];

  curl_close($ch);

  echo $filesize;
Run Code Online (Sandbox Code Playgroud)

Ref*_*gic 0

我以前遇到过这个问题,我使用的脚本可以在这里找到 - > http://boolean.co.nz/blog/curl-remote-filesize/638/。与上面的帖子相当相似,但更直接一点,而且更不宽容。