PHP FTP upload to specific folder

你说的曾经没有我的故事 提交于 2020-12-06 07:08:21

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!