我正在开发我的网络应用程序,让用户通过网址上传文件。 我想在实际下载整个内容之前知道文件的大小,因为我想将大小限制为100MB 如何在php或其他建议中使用curl执行此操作?感谢。
<?php
$url = 'http://www.example.com/video.mp4';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$size = // want to know file size here
if($size > 100 * 1024 * 1024) {
echo "The file you're trying to uplaod is greater than 100MB, please try another.";
exit;
}
file_put_contents(basename($url), file_get_contents($url));
?>