Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easiest way to grab filesize of remote file in PHP?

Tags:

I was thinking of doing a head request with cURL, was wondering if this is the way to go?

like image 987
meder omuraliev Avatar asked Sep 09 '09 18:09

meder omuraliev


People also ask

How to get fileSize in PHP?

To get the file size, we will use filesize() function. The filesize() function returns the size of a file in bytes. This function accepts the filename as a parameter and returns the size of a file in bytes on success and False on failure.

Which function is used to obtain the size of uploaded file in PHP?

The filesize() function returns the size of a file.

What is remote file in PHP?

Using remote files ¶ ini , you can use HTTP and FTP URLs with most of the functions that take a filename as a parameter. In addition, URLs can be used with the include, include_once, require and require_once statements (allow_url_include must be enabled for these).


1 Answers

The best solution which follows the KISS principle

$head = array_change_key_case(get_headers("http://example.com/file.ext", 1));
$filesize = $head['content-length'];
like image 118
softwarefreak Avatar answered Nov 11 '22 02:11

softwarefreak