note 71098 added to function.filesize
| From: | JoshFinlay | Date: | Sun, 12 Nov 2006 08:22:45 +0000 |
| Subject: | note 71098 added to function.filesize | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-119621@lists.php.net to get a copy of this message | ||
I know there has been alot of remote filesize snippets posted, but I'll post mine also.
It supports HTTP/HTTPS/FTP/FTPS and detects which type it should use. It needs --enable-ftp for the
FTP/FTPS functions.
I hope this works for someone.
<?php
function remotefsize($url) {
$sch = parse_url($url, PHP_URL_SCHEME);
if (($sch != "http") && ($sch != "https") && ($sch !=
"ftp") && ($sch != "ftps")) {
return false;
}
if (($sch == "http") || ($sch == "https")) {
$headers = get_headers($url, 1);
if ((!array_key_exists("Content-Length", $headers))) { return false; }
return $headers["Content-Length"];
}
if (($sch == "ftp") || ($sch == "ftps")) {
$server = parse_url($url, PHP_URL_HOST);
$port = parse_url($url, PHP_URL_PORT);
$path = parse_url($url, PHP_URL_PATH);
$user = parse_url($url, PHP_URL_USER);
$pass = parse_url($url, PHP_URL_PASS);
if ((!$server) || (!$path)) { return false; }
if (!$port) { $port = 21; }
if (!$user) { $user = "anonymous"; }
if (!$pass) { $pass = "phpos@"; }
switch ($sch) {
case "ftp":
$ftpid = ftp_connect($server, $port);
break;
case "ftps":
$ftpid = ftp_ssl_connect($server, $port);
break;
}
if (!$ftpid) { return false; }
$login = ftp_login($ftpid, $user, $pass);
if (!$login) { return false; }
$ftpsize = ftp_size($ftpid, $path);
ftp_close($ftpid);
if ($ftpsize == -1) { return false; }
return $ftpsize;
}
}
?>
----
Server IP: 203.202.10.60
Probable Submitter: 220.236.157.183
----
Manual Page -- http://www.php.net/manual/en/function.filesize.php
Edit -- https://master.php.net/note/edit/71098
Del: integrated -- https://master.php.net/note/delete/71098/integrated
Del: useless -- https://master.php.net/note/delete/71098/useless
Del: bad code -- https://master.php.net/note/delete/71098/bad+code
Del: spam -- https://master.php.net/note/delete/71098/spam
Del: non-english -- https://master.php.net/note/delete/71098/non-english
Del: in docs -- https://master.php.net/note/delete/71098/in+docs
Del: other reasons-- https://master.php.net/note/delete/71098
Reject -- https://master.php.net/note/reject/71098
Search -- https://master.php.net/manage/user-notes.php