Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
PHP: ftp_size - Manual
[go: Go Back, main page]

PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

ftp_ssl_connect" width="11" height="7"/> <ftp_site
Last updated: Sun, 25 Nov 2007

view this page in

ftp_size

(PHP 4, PHP 5)

ftp_size — 指定したファイルのサイズを返す

説明

int ftp_size ( resource $ftp_stream , string $remote_file )

ftp_size() は指定されたファイルのサイズを バイト数で返します。

注意: すべてのサーバがこの機能をサポートしているわけではありません。

パラメータ

ftp_stream

FTP 接続のリンク ID 。

remote_file

リモートファイル。

返り値

成功した場合はファイルのサイズを、エラー時には -1 を返します。

Example#1 ftp_size() の例

<?php

$file 
'somefile.txt';

// 接続を確立する
$conn_id ftp_connect($ftp_server);

// ユーザ名とパスワードでログインする
$login_result ftp_login($conn_id$ftp_user_name$ftp_user_pass);

// $file のサイズを取得する
$res ftp_size($conn_id$file);

if (
$res != -1) {
    echo 
"size of $file is $res bytes";
} else {
    echo 
"couldn't get the size";
}

// 接続を閉じる
ftp_close($conn_id);

?>

参考



ftp_ssl_connect" width="11" height="7"/> <ftp_site
Last updated: Sun, 25 Nov 2007
 
add a note add a note User Contributed Notes
ftp_size
miccots at gmail dot com
30-Oct-2007 06:55
2 adams[AT]techweavers[DOT]net:
To get a size of large file (f. ex.: 3.2 Gb) you have to format the result returned by ftp_size():

$size = sprintf ("%u", ftp_size($connection, $file_name));

So you can get the real size of big files. But this method is not good for checking is this a dir (when ftp_size() returns -1).
C_Muller
22-Jul-2007 07:42
For checking if a certain folder exists try using ftp_nlist() function to get a directory list in array. By using in_array('foldername') you can find out if it is there or not.
chuck at t8design dot com
24-May-2006 01:54
note that project_t4 at hotmail dot com's example above doesn't work in general, though it works on his Win2K/Apache server; as far as I can tell there is no way to check over ftp whether a directory exists.  This function's behavior given a directory name seems to be at least somewhat dependent on your OS, web server, or ftp server, I don't know which.
adams[AT]techweavers[DOT]net
22-Jun-2005 06:30
Well this function is nice but if you have files larger then 2.1Gb or 2.1 Billion Bytes you cannot get its size.
29-Sep-2004 10:10
To get a dirsize recursive you can use this simple function:

<?php # copyright by fackelkind | codeMaster
   
function getRecDirSize ($connection, $dir){
       
$temp = ftp_rawlist ($connection, "-alR $dir");
        foreach (
$temp as $file){
            if (
ereg ("([-d][rwxst-]+).* ([0-9]) ([a-zA-Z0-9]+).* ([a-zA-Z0-9]+).* ([0-9]*) ([a-zA-Z]+[0-9: ]*[0-9]) ([0-9]{2}:[0-9]{2}) (.+)", $file, $regs)){ 
               
$isdir = (substr ($regs[1],0,1) == "d");
                if (!
$isdir)
                   
$size += $regs[5];
            }
        }
        return
$size;
    }
   
$dirSize = getRecDirSize ($conID, "/");
?>
project_t4 at hotmail dot com
19-Mar-2004 04:03
Just to let people out there know, on my windows 2000 server running Apache and php i was returned 0 not -1 for directories.

foreach ($dir_list as $item)
    {
      if(ftp_size($conn_id, $item) == "0")
      {
      echo "<br>Directory:: ".$item;
      } else {
      echo "<br>File:: ".$item;
      }
    }

This outputs a list of the remote directory and indicates which items are directories and which are files.
nicke_ at at_h9k dot com
04-Oct-2003 10:48
This will return the filesize on remote host and the size if you download it in FTP_BINARY mode. If you are using FTP_ASCII in ftp_get() the size can be changed.
victor59 at yahoo dot com dot hk
23-Dec-2002 06:44
$file= 'filename with space.txt';
$size = ftp_size($this->ftp, urldecode($file) );

this one can correctly return the size
otherwize, it always return -1

ftp_ssl_connect" width="11" height="7"/> <ftp_site
Last updated: Sun, 25 Nov 2007
 
 
show source | credits | sitemap | contact | advertising | mirror sites