note 81900 added to function.filesize
| From: | bifor at free dot fr | Date: | Tue, 18 Mar 2008 20:22:15 +0000 |
| Subject: | note 81900 added to function.filesize | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-137181@lists.php.net to get a copy of this message | ||
If you need a function who can read the size of a link in the server and a external file ( from
world wide web )
<?php
function urlfilesize($url,$thereturn) {
if (substr($url,0,4)=='http') {
$x = array_change_key_case(get_headers($url, 1),CASE_LOWER);
$x = $x['content-length'];
}
else { $x = @filesize($url); }
if (!$thereturn) { return $x ; }
elseif($thereturn == 'mb') { return round($x / (1024*1024),2) ; }
elseif($thereturn == 'kb') { return round($x / (1024),2) ; }
}
$url = 'http://your-site/file.zip'; #
example
echo urlfilesize($url,'mb') ; # Will return the filesize of the link, in MegaByte.
echo urlfilesize($url,'kb') ; # Will return the filesize of the link, in KiloByte.
echo urlfilesize($url,'') ; # Will return the filesize of the link, in bytes
?>
It's quite simple to use ;)
Based on a function from http://www.tayo.fr/filesize-pour-une-url-aide.php
----
Server IP: 195.221.21.36
Probable Submitter: 88.160.22.187
----
Manual Page -- http://www.php.net/manual/en/function.filesize.php
Edit -- https://master.php.net/note/edit/81900
Del: integrated -- https://master.php.net/note/delete/81900/integrated
Del: useless -- https://master.php.net/note/delete/81900/useless
Del: bad code -- https://master.php.net/note/delete/81900/bad+code
Del: spam -- https://master.php.net/note/delete/81900/spam
Del: non-english -- https://master.php.net/note/delete/81900/non-english
Del: in docs -- https://master.php.net/note/delete/81900/in+docs
Del: other reasons-- https://master.php.net/note/delete/81900
Reject -- https://master.php.net/note/reject/81900
Search -- https://master.php.net/manage/user-notes.php