所以我在这里尝试向客户端发送一些从javascript接收的数组文件。我的问题是我无法重新定义文件名(因为它的标题)。所以例如,我想发送3个文件到客户端,第一个发送,然后我得到了最后一个错误。有谁知道如何解决它?这是我的PHP代码:
PHP
<?php
ignore_user_abort(true);
set_time_limit(0); // disable the time limit for this script
$path = "../temp/"; // change the path to fit your websites document structure
$data = escapeshellarg($_GET['File']);
$data = str_replace("\\","",$data); // remove useless characters inserted
$data = str_replace("\"","",$data); //
$dl_file = explode(",", $data);
header("Content-type: application/octet-stream");
header("Cache-control: private"); //use this to open files directly
header('Pragma: private');
for($i = 0; $i < count($dl_file); $i++)
{
$fullPath = $path.$dl_file[$i];
$path_parts = pathinfo($fullPath);
header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\"",true);
if ($fd = fopen ($fullPath, "r"))
{
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower($path_parts["extension"]);
ob_clean();
flush();
readfile($fullPath);
}
fclose ($fd);
}
exit;
?>
以下是我在服务器的日志文件中收到的错误:
Warning: Cannot modify header information - headers already sent in (php file path)