A
A
Alexander Razumov2018-10-05 14:47:51
PHP
Alexander Razumov, 2018-10-05 14:47:51

Is it possible to find out the size of a file, its type, without downloading the whole thing?

Is it possible, using curl, to find out the size of a file from a link (and other information) without downloading the entire file to the server? Is it technically possible. Thanks

Answer the question

In order to leave comments, you need to log in

5 answer(s)
A
Alexander Aksentiev, 2018-10-05
@razumovsu

if the server gives this information, then yes, and if it does not, then no.
Depends on who distributes the files shorter.
Well, infa in the headlines, respectively.

A
Andrey Burov, 2018-10-05
@BuriK666

https://ru.wikipedia.org/wiki/HTTP#HEAD

A
Askhat Bikmetov, 2018-10-05
@askhat

Of course, the first few bytes of the file are unique for each type, and the type can be calculated from them. Thanks to this property, for example, the library works libmagic.
https://gist.github.com/leommoore/f9e57ba2aa4bf197ebc5

V
vman, 2018-10-05
@vman

as an option

curl -m 1 -sS -D - -X HEAD https://hsto.org/r/w120/webt/5a/80/fd/5a80fd8c368f0954751429.png 2>/dev/null | grep -Po '(?<=Content-Length: )(\d+)|((?<=Content-Type: )[a-z\-]+/[a-z\-]+)'

image/png
12597

HEAD will not work if the target server sends a redirect. For such a task, it is better to implement a small script or application.

M
mlatushko, 2020-11-27
@mlatushko

wget --spider URL
Wget for Windows ( gnuwin32.sourceforge.net/packages/wget.htm )
Wget and cURL are included in the AWGG download program files ( https://videohelp.com/software/AWGG ) by five different engines/"engines" (Windows) .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question