Skip to content

Instantly share code, notes, and snippets.

@tieutantan
Last active February 15, 2019 13:50
Show Gist options
  • Save tieutantan/1beb4b976fb354595d6b0188e9836f9b to your computer and use it in GitHub Desktop.
Save tieutantan/1beb4b976fb354595d6b0188e9836f9b to your computer and use it in GitHub Desktop.
PHP get file size from remote URL without download
<?php
$url = 'https://speed.hetzner.de/100MB.bin';
$url = 'https://speed.hetzner.de/100MB.bin';
$url = 'https://speed.hetzner.de/10GB.bin';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_exec($ch);
$size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
curl_close($ch);
var_dump(($size));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment