没有办法想象你的就是你发布的代码才去上什么,但是,它会建议,如果你正在做一个下载,你要小心,不要输出任何文本(甚至白色空间),直到部分代码完全运行。在<?php
之前甚至有一个空格会引发错误。这里是一个函数,你可能想尝试一下(如果你愿意):
<?php
/**
* FULL-NAME OF THE FILE TO DOWNLOAD
* @param $downloadFileName
* NEW-NAME FOR THE FILE... DO NOT USE EXTENSIONS LIKE .pdf OR .doc OR .txt
* @param null $newFileName
* @return bool
*
*/
function processDownload($downloadFileName, $newFileName=null) {
$ext = pathinfo($downloadFileName, PATHINFO_EXTENSION);
if(!$newFileName){
$newFileName = basename($downloadFileName);
}else{
$newFileName .= "." . $ext;
}
if(file_exists($downloadFileName)){
$size = @filesize($downloadFileName);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $newFileName);
header('Content-Transfer-Encoding: binary');
header('Connection: Keep-Alive');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . $size);
readfile($downloadFileName);
return TRUE;
}
return FALSE;
}
如果您选择尝试这个功能,建议,使之成为第一个函数调用在脚本这样的顶部:
<?php
// NOTICE THAT THERE IS NO WHITE-SPACE BEFORE PHP.
// AND NO OUTPUT WAS SENT (IE: NOTHING ECHOED OUT...)
processDownload(__DIR__ . "/downloads/unique_ips.txt", "Unique-IPs");
// FROM HERE ON, YOU MAY ECHO WHATEVER YOU WISH...
// echo $whatever;
// echo $youWish;
// echo $may;
// echo $nowBeEchoed;
// echo $afterCalling;
// echo $theFunctionAbove;
echo 'IP addresses only found in file A:' . "\n";
echo $array_a_result . "\n\n";
echo 'IP addresses only found in file B:' . "\n";
echo $array_b_result;
function processDownload($downloadFileName, $newFileName=null) {
$ext = pathinfo($downloadFileName, PATHINFO_EXTENSION);
if(!$newFileName){
$newFileName = basename($downloadFileName);
}else{
$newFileName .= "." . $ext;
}
if(file_exists($downloadFileName)){
$size = @filesize($downloadFileName);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $newFileName);
header('Content-Transfer-Encoding: binary');
header('Connection: Keep-Alive');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . $size);
readfile($downloadFileName);
return TRUE;
}
return FALSE;
}
这里运行的是哪里?如果它没有在其他输出之前发送,那么它将不起作用 - 报头输出必须是发送的第一个输出。 –
你有没有尝试过为你的Content-type使用“application/octet-stream”? – Terry