问题
I want to upload all files to a specific directory
This script works fine
foreach (glob("*.*") as $filename)
{
ftp_put($ftp_conn, basename($filename), $filename, FTP_BINARY);
}
How to edit it to make it work to a specific directory? I tried this, but it didn't work:
// connect and login to FTP server
$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);
回答1:
The second param in ftp_put() should include the path and the filename.
foreach (glob("*.*") as $filename) {
$ftp_path = $ftp_path = '/public_html/'.$filename;
ftp_put($ftp_conn,$ftp_path , $filename, FTP_BINARY);
}
来源:https://stackoverflow.com/questions/31238318/php-ftp-upload-to-specific-folder