Skip to content

Instantly share code, notes, and snippets.

@mapyo
Last active August 29, 2015 14:16
Show Gist options
  • Save mapyo/c7f35cc3edb147dc7efa to your computer and use it in GitHub Desktop.
Save mapyo/c7f35cc3edb147dc7efa to your computer and use it in GitHub Desktop.
ftp_rawlistのバグ?
// $filePath = 'etc/[02].png'; // 存在するファイル
$filePath = 'etc/yusuke.jpeg'; // 存在するファイル
// $filePath = 'etc/hoge.jpeg'; // 存在しないファイル

$connection = ftp_connect($host, 21, 10);
ftp_login($connection, $user, $password);
$listing = ftp_rawlist($connection, $filePath);
var_dump($listing);

$size = ftp_size($connection, $filePath);
var_dump($size);

ftp_close($connection);

こんな感じのテストプログラム書いた。

$ php -v
PHP 5.3.29 (cli) (built: Feb 14 2015 00:34:40)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2014 Zend Technologies

# etc/[02].png
$ php test.php
array(0) {
}
int(11308)

# etc/yusuke.jpeg
$ php test.php
array(1) {
  [0]=>
  string(75) "-rw-r--r--   1 user user     7053 Dec 13  2013 etc/yusuke.jpeg"
}
int(7053)

# 存在しないファイルを指定した時
$ php test.php
bool(false)
int(-1)

問題点

  • etc/[02].pngを指定した時に何故ftp_rawlistは空の配列を返す?
  • でもちゃんとファイルサイズは返しているっぽい
@mapyo
Copy link
Author

mapyo commented Mar 12, 2015

手元のvagrant環境でftpサーバ構築して試したら、普通にftp_rawlistの値が返って来たので、これはサーバ側の設定の問題だった。。。ということでfix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment