我正在导出一些数据,制作文件并将数据写入文件...
我的文件出现在 FTP 服务器上,但它是空的...
这是代码。
//Connect to the FTP server
$ftpstream = @ftp_connect('localhost');
//Login to the FTP server
$login = @ftp_login($ftpstream, 'some_login', 'some_password');
if($login) {
//We are now connected to FTP server.
//Create a temporary file
$temp = tmpfile();
//Upload the temporary file to server
@ftp_fput($ftpstream, '/httpdocs/itineraryschedule.txt', $temp, FTP_ASCII);
//Make the file writable by all
ftp_site($ftpstream,"CHMOD 0777 /httpdocs/itineraryschedule.txt");
//Write to file
$fp = fopen('var/www/vhosts/cruiseandmaritime.com/httpdocs/itineraryschedule.txt', 'w');
fputs($fp, 'some data');
fclose($fp);
//Make the file writable only to owner
ftp_site($ftpstream,"CHMOD 0644 /httpdocs/itineraryschedule.txt");
}
我很困惑!
丰富的:)
删除 @ 以查看是否发生任何错误
也是你的道路
$fp = fopen('var/www/vhosts/cruiseandmaritime.com/httpdocs/itineraryschedule.txt', 'w');
似乎有点不对劲
$fp = fopen('/var/www/vhosts/cruiseandmaritime.com/httpdocs/itineraryschedule.txt', 'w');
或?
我不知道
你正在使用的库。但是代码似乎在上传之前上传了您刚刚创建的 tmpfile()。这就是它是空的。
您似乎将要推送的数据写入本地FTP服务器。 var/www/vhosts/cruiseandmaritime.com/httpdocs/itineraryschedule.txt
只是在您的机器上。尝试用ftp_fput
上传它 - 这应该可以解决问题。