set_time_limit 300 class index private static host oni myftp org login

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
set_time_limit(300);
class index {
private static $host = 'oni.myftp.org', $login = 'psykick', $pwd = 'psywelcome', $root;
private static $list = array (), $ftp;
private $i = 0, $index = array (), $info;
public function index() {
self::$ftp = ftp_connect ( self::$host, '21', '100' );
if (! ftp_login ( self::$ftp, self::$login, self::$pwd ))
exit ( "err" );
self::$root = 'ftp://'.self::$login.':' . self::$pwd . '@' . self::$host;
}
private function scan($dir) {
$ret = array ();
$i = 0;
$tmp = ftp_nlist ( self::$ftp, $dir );
foreach ( $tmp as $f ) {
$fullPath = self::$root . '/'. $dir . '/' . $f;
if (substr ( $f, - 3 ) == 'mp3') {
$info = preg_split ( '/(-\d+-|_-_|-)/', preg_replace('/^(\d+[\-_])?/','', $f) );
/*$ret [$i++] = array (
'artist' => $info[0],
'name' => trim(preg_replace('/(_|\.mp3$)/',' ',$info[1])),
'link' => $fullPath
);*/
$i++;
echo '<p><a href="' . $fullPath . '">' . $info[0] . ' &ndash; ' . trim(preg_replace('/(_|\.mp3$)/',' ',$info[1])) . '</p>';
} else if( is_dir($fullPath) && ++$this->i < 100) {
$this->scan($dir . '/' . $f );
continue;
}
}
if($i)
$this->index = array_merge($this->index, $ret);
return $this->index;
}
public function close() {
$this->scan('ZeroDay/2009');
//var_dump ( );
ftp_close ( self::$ftp );
}
}