0

所以 $fmain 等于文件路径,和随机生成的文件名,然后 fwrite 100 行 html 文字(使用 ' ')。这很好,但它随后保存到服务器,这很好,但随后它下载到客户端(请求文件下载的客户端)并且它是空白的。有没有人有任何想法?顺便说一句,这一切都在同一页上。该文件在服务器本身上是完整的,但在下载到客户端时不是。

fwrite($file, $line98 );
fwrite($file, $numberNewline);
fwrite($file, $line99 );
fwrite($file, $numberNewline);
fwrite($file, $line100 );
fwrite($file, $numberNewline);



fclose($file);

if (file_exists($fmain)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($fmain));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($fmain));
ob_clean();
flush();
exit;
}
4

1 回答 1

1

您的脚本只是发送标头,您readfile还应该在ob_clean(). 例如它可能是:

if (file_exists($fmain)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($fmain));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($fmain));
readfile($fmain);
ob_clean();
flush();
exit;
}
于 2013-09-08T06:50:24.017 回答