ftp_size
(PHP 4, PHP 5, PHP 7, PHP 8)
ftp_size — 返回指定檔案的大小
說明
ftp_size(resource
$ftp
, string $filename
): intftp_size() 函式返回指定檔案的大小(以位元組為單位)。
注意:
不是所有伺服器都支援該功能。
參數
-
ftp
-
FTP 連線的鏈接識別符號。
-
filename
-
遠端檔案。
返回值
成功時返回檔案大小,錯誤返回 -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 "size of $file is $res bytes";
} else {
echo "couldn't get the size";
}
// 關閉連線
ftp_close($conn_id);
?>