为什么我的while循环不输出$st['status']
的值?
正在成功下载这两个文件。
json_encode($st)
不输出任何内容。
while (true) {
clearstatcache();
# Get filesize
$fileSize = ftp_size($conn_id, $txt_filename);
# Check if txt (status) file exist
# Filesize will return -1 if no file exist
if($fileSize == -1) {
$st['status'] = 'no file';
# no file
return true; // continue loop until file exist
}else{
# File exist
# Move remote files (xml and txt) to local folder
# Download both txt and xml files
if(
ftp_get($conn_id, $localstatusfolder.'/'.$txt_filename, $txt_filename, FTP_BINARY) &&
ftp_get($conn_id, $localstatusfolder.'/'.$xml_filename, $xml_filename, FTP_BINARY)
) {
# Files downloaded to local folder
$st['status'] = 'ok';
ftp_close($conn_id);
return false;
}else{
# Fejl, ftp_get
$st['status'] = 'FTP003';
ftp_close($conn_id);
return false;
}
}
}
echo json_encode($st);
答案 0 :(得分:0)
这些行中有错误,
ftp_get($conn_id, $localstatusfolder.'/'.$txt_filename, $txt_filename, FTP_BINARY) &&
ftp_get($conn_id, $localstatusfolder.'/'.$xml_filename, $xml_filename, FTP_BINARY)
尝试删除这些行,然后检查并删除代码中的return false
,这意味着代码不会在此后运行。使用适用于此情况的break
。