ftp_size

(PHP 3 >= 3.0.13, PHP 4, PHP 5)

ftp_size -- Возвращает размер файла

Описание

int ftp_size ( resource ftp_stream, string remote_file )

ftp_size() возвращает размер заданного файла в байтах.

Замечание: Не все FTP серверы поддерживают эту возможность.

Список параметров

ftp_stream

Идентификатор соединения с FTP сервером

remote_file

Имя файла на сервере

Возвращаемые значения

Возвращает размер файла, или -1 при возникновении ошибки.

Примеры

Пример 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
"Рамер файла $file  $res байт";
} else {
   echo
"Не удалось определить размер файла $file";
}

// закрытие соединения
ftp_close($conn_id);

?>

Смотрите также

ftp_rawlist()



ftp_size
chuck at t8design dot com
23-May-2006 09: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
21-Jun-2005 02: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.
28-Sep-2004 06: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
18-Mar-2004 11: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
03-Oct-2003 06: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 01: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_siteftp_ssl_connect>
 Last updated: Tue, 15 Nov 2005