我有一个PHP脚本:
一切正常,文本文件中包含数据。 通过FTP发送文件时,文件在接收服务器上创建,但是为空。
这是相关代码:
if ($result = mysqli_query($db,$qry)){
echo "Found Records</br>";
$fd1 = fopen($fpath.$filename1, "w+");
$fd2 = fopen($fpath.$filename2, "w+");
while ($row = $result->fetch_assoc()) {
// Populate text files with data
...
}
}
mysqli_close($db);
//FTP text files to another server
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);
if (ftp_fput($ftp_conn, $filename1, $fd1, FTP_ASCII)) {
echo "Successfully uploaded $filename1\n";
} else {
echo "There was a problem while uploading $filename1\n";
}
if (ftp_fput($ftp_conn, $filename2, $fd2, FTP_ASCII)) {
echo "Successfully uploaded $filename2\n";
} else {
echo "There was a problem while uploading $filename2\n";
}
ftp_close($ftp_conn);
fclose($fd1);
fclose($fd2);
答案 0 :(得分:0)
关闭文件流后,我能够使其工作 并使用 ft_put()代替 ft_fput()