Actions

API16

JFilesystemHelper/remotefsize

From Joomla! Documentation

< API16:JFilesystemHelper
Revision as of 00:07, 13 May 2013 by JoomlaWikiBot (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Remote file size function for streams that don't support it http://www.php.net/manual/en/function.filesize.php#71098


[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Syntax

remotefsize($url)
Parameter Name Default Value Description
$url

Defined in

libraries/joomla/filesystem/helper.php

Importing

jimport( 'joomla.filesystem.helper' );

Source Body

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 = ""; }
                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;
        }
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples

<CodeExamplesForm />