Hello
How can I get size of a file which website?
Example:
http://www.website/file.zip
How can I get size of file.zip?
Thx
Printable View
Hello
How can I get size of a file which website?
Example:
http://www.website/file.zip
How can I get size of file.zip?
Thx
filesize() doesn't work for files on websites.
Sorry, didn't read carefully enough.
You can't get the size of files on remote websites. Not easily and reliably, anyway
If the response sends a Content-Length header then you can get the size. This is not necessarily the size of the file though, it is the size f the response body.
If there is no Content-Length header, you'll need to download the entire file first.
How can I do it by using Content-Length?Quote:
Originally Posted by visualAd
i am going to work now. I will reply when I get back. If pena doesn't beat me to it.
Could you do it?Quote:
Originally Posted by visualAd
Thanks
You can use the stream_get_meta_data() function to get the heads from an fopen wrapper.
PHP Code:if (!($fp = @fopen($url, 'r'))) {
/* error here - as url could not be opened */
}
$metaData = stream_get_meta_data($fp);
$size = null;
foreach ($metaData['wrapper_data'] as $header) {
if (strpos(strtolower($header), 'content-length') !== false) {
$size = substr($header, strpos($header, ':') + 1);
break;
}
}
if (is_null($size)) {
/* Content-Length header not found */
}
Thanks