I'm developing my web application which let user to upload file via a url.
I want to know the file's size before I actually download whole contents because i want to limit size at 100MB.
How can I do this with curl in php or other suggest? Thanks.
<?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));
?>