Last active
February 15, 2019 13:50
-
-
Save tieutantan/1beb4b976fb354595d6b0188e9836f9b to your computer and use it in GitHub Desktop.
PHP get file size from remote URL without download
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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