我正在开发一个基于CodeIgniter的web应用程序,并且我正在实现下载管理中的车辆图像的zip文件的功能,以传递给第三方派对。可以在PHP中创建zip存档,但无法正确下载
我可以毫无问题地创建zip存档 - 如果我注释掉后面的部分,我可以看到zip文件被创建并包含正确的文件,并且可以正常提取。
但是,允许用户在创建文件后下载该文件是非常棘手的。我已经实现了允许与要下载的正确名称的文件,但它的错误时,以下消息解压:
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
任何想法,我已经错了吗?我在网上查了多篇教程,并找不到问题出在哪里。
public function downloadvehicleimages()
{
// If logged in...
if ($this->adminuser)
{
// Get data
$usedcars = $this->adminmodel->getUsedCarsWithLimit();
// Get the registrations for these vehicles
$registrations = array();
foreach($usedcars->result_array() as $usedcar)
{
array_push($registrations, $usedcar['Registration']);
}
// Get all the images for these registrations
$images = array();
$original_dir = getcwd();
chdir('../used-cars/static/images/custom/');
foreach($registrations as $registration)
{
$vehicle_images = glob(strtoupper($registration) . '_*.jpg');
sort($vehicle_images);
foreach($vehicle_images as $vehicle_image)
{
array_push($images, $vehicle_image);
}
}
// Zip them up
$zipname = 'images.zip';
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);
foreach($images as $image)
{
$zip->addFile($image);
}
$zip->close();
// Let user download the file
$this->output->set_header('Content-Type: application/zip');
$this->output->set_header('Pragma: no-cache');
$this->output->set_header('Expires: 0');
$this->output->set_header("Content-Disposition: attachment;filename='$zipname'");
$this->output->set_header('Content:Length: ' . filesize($zipname));
unlink($zipname);
chdir($original_dir);
}
}
我会接受的答案的人只是把,但它删除了 – 2014-10-08 10:00:13