我需要使用PHP将所有.ch文件(位于特定文件夹中)从我的FTP服务器提取到我的网站。我可以收到一些关于如何做的指导吗?
答案 0 :(得分:0)
从PHP手册中阅读这些basic examples后,您可以使用此代码的部分内容:
<?php
$dir = "/ftpdir/source/";
$dir1= "/websitedir/newfolder/"
// Open a directory, and read its contents
if (is_dir($dir)){
if ($dh = opendir($dir)){
while (($file = readdir($dh)) !== false){
//Check the file extension, several methods available
$ext=pathinfo($dir.$file);
// If the extension is ch, then copy the file
if($ext == "ch") {
if(copy($dir.$file,$dir1.$file)) {
echo $dir.$file." has been copied to ".$dir1.$file."<br>";
}
else { echo "Something went wrong.<br>"; }
}
}
closedir($dh);
}
}
?>
我希望这会对你有所帮助。
答案 1 :(得分:0)
请检查:http://php.net/manual/en/function.ftp-nlist.php
示例:
<?php
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// get contents of the current directory
$contents = ftp_nlist($conn_id, ".");
// output $contents
var_dump($contents);
?>
您可以使用if($something == "ch") {...}