我已经写了下面的代码连接到FTP,这给了我一个错误“警告:的preg_match()[function.preg匹配]:未知的修饰词‘P’”FTP用PHP下载多个文件
<?php
// define some variables
$ftp_server="www.abc.com";
$ftp_user_name="username";
$ftp_user_pass="password";
$local_file = 'L021-D8127-BLUEWASH-2T.jpg';
$server_file = '/abc/photos/L021-D8127-BLUEWASH-2T.jpg';
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
//
//Enable PASV (Note: must be done after ftp_login())
//
$mode = ftp_pasv($conn_id, TRUE);
// get contents of the current directory
$contents = ftp_nlist($conn_id, "abc/photos");
// output $contents
//var_dump($contents);
foreach($contents as $file){
if(!preg_match("/L021-D8127-BLUEWASH-([1-9]|10)(T|S)\.jpg/i", $file)){
// continute if its not the file I want to download
continute;
}
// try to download file and save to $local_file
if (ftp_get($conn_id, $local_file, file, FTP_BINARY)) {
echo "Successfully written to $local_file\n";
}
else {
echo "There was a problem\n";
}
}
// close the connection
ftp_close($conn_id);
?>
论 “照片” 的服务器文件夹我有相同的图像,但与像
L021-D8127-BLUEWASH-2T.jpg
L021-D8127-BLUEWASH-3T.jpg不同的名称序列的多个实例
L021-D8127-BL UEWASH-4T.jpg
并以此类推,直到10T.jpg
而且同样...
L021-D8127-BLUEWASH-2S.jpg
L021-D8127-BLUEWASH-3S.jpg
L021-D8127-BLUEWASH-4S.jpg
并以此类推,直到10S.jpg
我的问题是一个单一的FTP连接开豪我是否做..
1)检查是否所有发生的L021-D8127-BLUEWASH-(1 t0 10)T.jpg & L021-D8127-BLUEWASH-(1 t0 10)S.jpg存在。
2)如果图像存在下载所有匹配的文件
3)我不想同时使用20个FTP连接?
这是因为你不是逃避'/'中的preg_match。我在回答评论中告诉过你。 – 2012-02-12 12:11:47