我正在尝试在下载后删除zip文件。我尝试以下代码。但它显示错误
$response = new \Zend\Http\Response\Stream();
$response->setStream(fopen($zipname, 'r'));
$response->setStatusCode(200);
$headers = new \Zend\Http\Headers();
$headers->addHeaderLine('Content-Type', 'application/octet-stream')
->addHeaderLine('Content-Disposition', 'attachment; filename='.basename($zipname))
->addHeaderLine('Content-Length', filesize($zipname));
$response->setHeaders($headers);
unlink($zipname);
return $response;
下载后,当我在记事本中打开下载的文件时,显示如下:
取消关联(D:\ xampp \ htdocs \ medgenom \ development \ uploads / Bulk_formE_Download_0.91481200 1474869559.zip):权限被拒绝
答案 0 :(得分:0)
我使用以下代码解决了
header('Content-Type', 'application/octet-stream');
header("Content-Disposition: attachment; filename=".basename($zipname));
header('Content-Length', filesize($zipname));
header("Pragma: no-cache");
header("Expires: 0");
readfile($zipname);
unlink($zipname);