我正在尝试使用从stackoverflow复制的以下代码将我的本地文件上传到服务器。我无法正确映射文件并寻求帮助。
我有两个带有$ localfile的测试用例。
代码:
//$local_file = 'C:\Program Files\EasyPHP-DevServer-14.1VC11\data\localweb\projects\alaks\filestoanotherserver\sample.csv';
//Warning: ftp_put(): Prohibited file name: C:\Program Files\EasyPHP-DevServer-14.1VC11\data\localweb\projects\alaks\filestoanotherserver\sample.csv in C:\Program Files\EasyPHP-DevServer-14.1VC11\data\localweb\projects\alaks\filestoanotherserver\test.php on line 28
// The filename that i got the php code is test.ph
$local_file = 'sample.csv';
//Connected!Successfully written to sample.csv - but not written.
//The file size is showing 0KB.
$server_file = 'http://iseedtechnologies.in/sample.csv';
// set up basic connection
$conn_id = ftp_connect("iseedtechnologies.in");
// login with username and password
$login_result = ftp_login($conn_id, '****', '****');
echo is_array(ftp_nlist($conn_id, ".")) ? 'Connected!' : 'not Connected! :(';
ftp_pasv($conn_id, true);
// try to download $server_file and save to $local_file
if (ftp_put($conn_id, $local_file, $server_file, FTP_BINARY)) {
echo "Successfully written to $local_file\n";
} else {
echo "There was a problem\n";
}
// close the connection
ftp_close($conn_id);
?>
工作代码(删除了http://并且有效)
$local_file = 'sample.csv';
$server_file = 'sample.csv';
// set up basic connection
$conn_id = ftp_connect("iseedtechnologies.in");
// login with username and password
$login_result = ftp_login($conn_id, '****', '****');
echo is_array(ftp_nlist($conn_id, ".")) ? 'Connected!' : 'not Connected! :(';
ftp_pasv($conn_id, true);
// try to download $server_file and save to $local_file
if (ftp_put($conn_id, $local_file, $server_file, FTP_BINARY)) {
echo "Successfully written to $local_file\n";
} else {
echo "There was a problem\n";
}
// close the connection
ftp_close($conn_id);
?>