Hello, I need to download a zip file.
$file = tempnam(sys_get_temp_dir(), “TMP0”);
$filesystemZip = new Filesystem(new ZipArchiveAdapter($file));
foreach ($contents as $object) {
$file_path = $object[‘path’];
$contentsP = $filesystem->read($file_path);
$filesystemZip->put($file_path, $contentsP);
}
$filesystemZip->getAdapter()->getArchive()->close();
$fh = fopen($file, ‘rb’);
$stream = new \Slim\Http\Stream($fh); // create a stream instance for the response body
unlink($file);
$response = $response->withHeader(‘Content-Type’, ‘application/zip’);
//$response = $response->withHeader(‘Content-Type’, ‘application/octet-stream’);
//$response = $response->withHeader(‘Content-Type’, ‘application/download’);
// $response = $response ->withHeader(‘Content-Description’, ‘File Transfer’);
//$response = $response ->withHeader(‘Content-Transfer-Encoding’, ‘Binary’);
$response = $response ->withHeader(‘Content-Disposition’, ‘attachment; filename= test.zip’);
//$response = $response->withHeader(‘Expires’, ‘0’);
//$response = $response->withHeader(‘Cache-Control’, ‘must-revalidate, post-check=0, pre-check=0’);
//$response = $response->withHeader(‘Pragma’, ‘no-cache’);
//$response = $response->withHeader(‘Content-length’,$stream->getSize());
//$response = $response->withBody($stream);
return $response->withBody($stream);
}
the problem is that the file has a first caracter ‘/t’ and I dont no way.
I use linux and centos 7.
Help please.