PHP の標準関数を目的別に調べることができる辞典

ホーム > PHP 標準関数逆引き辞典 > FTP > FTP サーバ上のファイルのサイズを取得する

PHP 標準関数逆引き辞典

:: reverse dictionary ::

FTP

※ソースファイルについて


FTP サーバ上のファイルのサイズを取得する

FTP サーバ上のファイルのサイズを取得するには、ftp_size 関数を使います。

≪ディレクトリ構造(サンプル)≫

D:ディレクトリ  F:ファイル

                    [サイズ]
D /
└ D public_html
   ├ F index.html     1966
   ├ F samp01.zip   178834
   └ F samp02.zip   338954
$host = $_REQUEST["host"];
$username = $_REQUEST["username"];
$password = $_REQUEST["password"];

// FTP 接続を開く
$ftps = ftp_connect($host);
$result = ftp_login($ftps, $username, $password);
if (!$result) {
  echo "接続に失敗しました。\n";
  return;
}

// ファイルのサイズを取得(絶対パス)
$sza = ftp_size($ftps, "/public_html/index.html");

// ファイルのサイズを取得(相対パス)
ftp_chdir($ftps, "/public_html");
$szb = ftp_size($ftps, "samp01.zip");
$szc = ftp_size($ftps, "samp02.zip");

// FTP 接続を閉じる
ftp_quit($ftps);

ソースファイル

$sza1966$szb178834$szc338954 になります。

▼ 関数

int ftp_size(resource ftps, string f)

FTP サーバ上のファイル f のサイズを取得します。

サイズの取得に失敗した場合は -1 を返します。
(ファイルが存在しない場合など)

●引数

ftps … FTP ストリーム
f … サイズを取得するファイル

●戻り値

・取得に成功 … ファイル f のサイズ(バイト単位)
・取得に失敗 … -1

●バージョン

PHP3(3.0.13 以降)、PHP4 、PHP5

注目キーワード ベスト5

  1. セキュリティ
  2. ホスティング
  3. レンタルサーバ
  4. ファイル復旧
  5. ハードディスク修復

FTP - file transfer protocol -


ホーム > PHP 標準関数逆引き辞典 > FTP > FTP サーバ上のファイルのサイズを取得する

Copyright (C) 2005-2007 Noto Watabe. All rights reserved.
e-mail:wmh@always-pg.com