我想将所有文件上传到特定目录
这个脚本工作正常
foreach (glob("*.*") as $filename)
ftp_put($ftp_conn,basename($filename) , $filename, FTP_BINARY);
如何编辑它以使其适用于特定目录我试过这个但是没有用:
//连接并登录FTP服务器
$usr = '*****';`enter code here`
$pwd = '******';
$ftp_server = "*******";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, $usr, $pwd);
$ftp_path = '/public_html/';
foreach (glob("*.*") as $filename)
ftp_put($ftp_conn,$ftp_path , $filename, FTP_BINARY);
// check upload status:
print (!$upload) ? 'Cannot upload' : 'Upload complete';
print "\n";
// close connection
ftp_close($ftp_conn);
答案 0 :(得分:4)
ftp_put()
中的第二个参数应包含路径和文件名。
foreach (glob("*.*") as $filename) {
$ftp_path = $ftp_path = '/public_html/'.$filename;
ftp_put($ftp_conn,$ftp_path , $filename, FTP_BINARY);
}