【PHP】FTP相关的代码 分类: php 2015-02-08 17:58 29人阅读 评论(0) 收藏

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Mirror update</title>
</head>

<body>
<?php
// set up variables - change these to suit application
$host = 'localhost';
$user = 'test';
$password = 'test';

$conn = ftp_connect($host);
if(!$conn)
{
    echo "ERROR: could not connect to ftp srver<br/>";
    exit;
}
echo "Connected to $host<br />";

//log in to host

$result = @ftp_login($conn,$user,$password);
if(!$result)
{
    echo "Error: Could nont log on as $user<br />";
    ftp_quit($conn);
    exit;
}
echo "Logged in as $user<br />";

// check file times to see if an update is required

//echo "Checking file time...<br/>";
echo "list of file<br>";

$listing = ftp_nlist($conn,'');

foreach($listing as $filename)
{
    $filename = iconv("GB2312","UTF-8",$filename);
    echo $filename."<br>";
}

//var_dump($listing);

//$temp = $listing[0];
//$encode = mb_detect_encoding($temp, array("ASCII","UTF-8","GB2312","GBK","BIG5")); 
/*  检测字符编码
三个参数分别是:被检测的输入变量、编码方式的检测顺序(一旦为真,后面自动忽略)、strict模式
对编码检测的顺序进行调整,将最大可能性放在前面,这样减少被错误转换的机会。
一般要先排gb2312,当有GBK和UTF-8时,需要将常用的排列到前面。 */
/*$temp = iconv("GB2312","UTF-8",$temp);
echo $temp."<br>";
echo $encode;*/
?>
</body>
</html>

版权声明:本文为博主原创文章,未经博主允许不得转载。

posted @ 2015-02-08 17:58  冰00封  阅读(100)  评论(0编辑  收藏  举报