好的,所以我有一个脚本可以运行并从我的数据库生成一个 csv 文件,当它从它下载的浏览器运行时,很好。
但我想将文件从我的服务器发布到另一台服务器。
我一直在尝试用这段代码来做,但它似乎不起作用,没有写入文件。即使 FTP 帐户详细信息也错误,登录 OK 也会返回..
// header("Content-type: application/octet-stream");
// header("Content-Disposition: attachment; filename=sailings.txt");
// header("Pragma: no-cache");
// header("Expires: 0");
// print "$header\n$data";
//Connect to the FTP server
$ftpstream = ftp_connect('ftp server address');
//Login to the FTP server
$login = ftp_login($ftpstream, 'user', 'password');
if($login) {
echo "logged in ok";
//We are now connected to FTP server.
//Create a temporary file
$temp = tmpfile();
fwrite($temp, $header."\n");
fwrite($temp, $data);
fseek($temp, 0);
echo fread($temp, 0);
//Upload the temporary file to server
ftp_fput($ftpstream, '/sailings.txt', $temp, FTP_ASCII);
//Make the file writable only to owner
ftp_site($ftpstream,"CHMOD 0644 /sailings.txt");
}
//Ftp session end
fclose($temp);
ftp_close($ftpstream);
请问谁能给我建议?
谢谢
富有的 :)