So here i'm trying to send to the client some files received in a array from javascript. My problem is that i cannot redefine the filename (since its a header). So for example, i wanna send 3 files to the client, the first one is sent, then i got a error for the 2 last. Does anyone have idea how to fix it? Here is my php code:
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;
?>
Here is the error i got in logs file of the server :
Warning:  Cannot modify header information - headers already sent in (php file path)
