Php opencart自定义下载错误

Php opencart自定义下载错误,php,download,opencart,Php,Download,Opencart,我的自定义下载按钮已停止工作, 如果我点击下载按钮,它应该下载一个zip文件 downloadZip的函数是 public function downloadZip() { $products=$this->session->data['products']; $attributes=$this->session->data['attributes']; /* ------------------- CSV

我的自定义下载按钮已停止工作, 如果我点击下载按钮,它应该下载一个zip文件

downloadZip的函数是

    public function downloadZip()
    {
        $products=$this->session->data['products'];
        $attributes=$this->session->data['attributes'];
        /* -------------------  CSV ------------------------*/
        header("Pragma: no-cache");
        header('Content-Type: text/csv;');
        $csv_filename = "image/".$this->request->get['catalogno'].".csv";
        $output = fopen($csv_filename, "w"); //Opens and clears the contents of file; or creates a new file if it doesn't exist
        $i=0;
        $temp_data[$i][]='Model';
        $temp_data[$i][]='Price';
        foreach ($attributes as $attribute)
        {
            $temp_data[$i][]=$attribute['name'];
        }
        $i++;
        foreach ($products as $key => $row)
        {
            $mid[$key]  = $row['model'];
        }
        array_multisort($mid, SORT_ASC, $products);
        foreach ($products as $product)
        {
            $temp_data[$i][]=$product['model'];
            $temp_data[$i][]=$product['pprice'];
            if(!empty($product['attribute_groups']))
            {
                foreach ($product['attribute_groups'] as $attribute_group)
                {
                    foreach ($attribute_group['attribute'] as $attribute)
                    {
                        foreach ($attributes as $attr)
                        {
                            if($attr['name'] == $attribute['name'])
                            {
                                $temp_data[$i][]=$attribute['text'];
                            }
                        }
                    }
                }
            }
            else
            {
                foreach ($attributes as $attribute)
                {
                    $temp_data[$i][]=' - ';
                }
            }
            $i++;
        }
        // Exporting the CSV
        foreach($temp_data as $row)
        {
            fputcsv($output, $row); // here you can change delimiter/enclosure
        }
        //fclose($output); // Closing the File
        /*------------------- End CSV --------------------*/
        /*------------------- Start HTML --------------------*/
        $f = fopen("image/Catalog".$this->request->get['catalogno'].".html", "w");
        $details='';
                    foreach ($products as $key => $row)
                    {
                        $mid[$key]  = $row['model'];
                    }
                    array_multisort($mid, SORT_ASC, $products);
                    $details.="<table>
                        <tr>
                            <td colspan='".(count($attributes)+2)."' align='center'><h1>Catalog</h1></td>
                        </tr>
                        <tr>
                            <th>Model</th>
                            <th>Price</th>";
                            foreach ($attributes as $attribute)
                                {
                                    $details.="<th>".$attribute['name']."</th>";
                             }
                        $details.="</tr>";
                   foreach ($products as $product) {
                      if($product['sspecial'])
                      {
                            $rate=$product['sspecial'];
                      }
                      else
                      {
                            $rate=$product['pprice'];
                      }
                        $details.="<tr>
                            <td>".$product['model']."</td>
                            <td>".$rate."</td>";
                if(!empty($product['attribute_groups']))
                    {
                        foreach ($product['attribute_groups'] as $attribute_group)
                        {
                         foreach ($attribute_group['attribute'] as $attribute)
                            {
                                foreach ($attributes as $attr)
                                {
                                    if($attr['name'] == $attribute['name'])
                                    {
                                        $details.="<td>".$attribute['text']."</td>";
                                    }
                                }
                           }
                       }
                   }
                   else
                   {
                        foreach ($attributes as $attribute) {
                            $details.="<td> - </td>";
                        }
                   }
               }
               $details.="</tr>
               </table>";
    $details .="<style>
table
{
    width:100%;
}
table tr td,table tr th {
    border:1px dashed #999;
    padding:5px 10px;
}
</style>";
        // Write text line
        fwrite($f, $details);
        // Close the text file
        fclose($f);
        /*------------------- END HTML --------------------*/
        unset($this->session->data['products']);
        unset($this->session->data['attributes']);
        $this->load->model('catalog/product');
        $this->load->model('tool/image');
        $productData = $this->model_catalog_product->getProductAllImages($this->request->get['catalogno']);
        //$result = $this->create_zip($productData,'my-archive.zip');
        $zip = new ZipArchive;
        $zip_name = "image/Catalog".$this->request->get['catalogno'].".zip";
        if ($zip->open($zip_name,  ZipArchive::CREATE)) {
            foreach($productData as $key=>$image)
            {
                $filename = substr(strrchr($image['image'], "/"), 1);
                $zip->addFile("image/".$image['image'], $filename);
            }
            $zip->addFile("image/Catalog".$this->request->get['catalogno'].".html","Catalog".$this->request->get['catalogno'].".html");
            $zip->addFile("image/".$this->request->get['catalogno'].".csv",$this->request->get['catalogno'].".csv");
            $zip->close();
            header($_SERVER['SERVER_PROTOCOL'].' 200 OK');
            header("Content-Type: application/zip");
            header("Content-Transfer-Encoding: Binary");
            header("Content-Length: ".filesize($zip_name));
            header("Content-Disposition: attachment; filename=\"".basename($zip_name)."\"");
            readfile($zip_name);
            unlink($zip_name);
            unlink("image/Catalog".$this->request->get['catalogno'].".html");
            unlink($csv_filename);
        } else {
            return false;
        }
        $this->index();
    }
公共函数下载zip()
{
$products=$this->session->data['products'];
$attributes=$this->session->data['attributes'];
/*-------------------CSV------------------------*/
标题(“杂注:无缓存”);
标题('Content-Type:text/csv;');
$csv_filename=“image/”$this->request->get['catalogno'].“.csv”;
$output=fopen($csv_filename,“w”);//打开并清除文件内容;如果文件不存在,则创建新文件
$i=0;
$temp_data[$i][]='Model';
$temp_data[$i][]=“价格”;
foreach($attributes作为$attribute)
{
$temp_data[$i][]=$attribute['name'];
}
$i++;
foreach($key=>$row形式的产品)
{
$mid[$key]=$row['model'];
}
数组\多端口($mid,排序\ ASC,$products);
foreach($products as$product)
{
$temp_data[$i][]=$product['model'];
$temp_数据[$i][]=$product['pprice'];
如果(!empty($product['attribute_groups']))
{
foreach($product['attribute\u group']作为$attribute\u group)
{
foreach($attribute_group['attribute']作为$attribute)
{
foreach($attr属性为$attr)
{
如果($attr['name']=$attribute['name']))
{
$temp_data[$i][]=$attribute['text'];
}
}
}
}
}
其他的
{
foreach($attributes作为$attribute)
{
$temp_data[$i][]='-';
}
}
$i++;
}
//导出CSV
foreach($temp_数据为$row)
{
fputcsv($output,$row);//您可以在这里更改分隔符/存储模块
}
//fclose($output);//关闭文件
/*-------------------结束CSV--------------------*/
/*-------------------启动HTML--------------------*/
$f=fopen(“图像/目录”。$this->request->get['catalogno']..html”,“w”);
$details='';
foreach($key=>$row形式的产品)
{
$mid[$key]=$row['model'];
}
数组\多端口($mid,排序\ ASC,$products);
$details.=”
目录
模型
价格”;
foreach($attributes作为$attribute)
{
$details.=''.$attribute['name'].'';
}
$details.=”;
foreach($products as$product){
如果($product['sspecial']))
{
$rate=$product['sspecial'];
}
其他的
{
$rate=$product['pprice'];
}
$details.=”
“$product['model']”
“$rate。”;
如果(!empty($product['attribute_groups']))
{
foreach($product['attribute\u group']作为$attribute\u group)
{
foreach($attribute_group['attribute']作为$attribute)
{
foreach($attr属性为$attr)
{
如果($attr['name']=$attribute['name']))
{
$details.=''.$attribute['text'].'';
}
}
}
}
}
其他的
{
foreach($attributes作为$attribute){
$details.=“-”;
}
}
}
$details.=”
";
$details.=”
桌子
{
宽度:100%;
}
表tr td,表tr th{
边框:1px虚线#999;
填充物:5px10px;
}
";
//写文本行
fwrite($f,$details);
//关闭文本文件
外国法郎(f美元);
/*-------------------结束HTML--------------------*/
取消设置($this->session->data['products');
取消设置($this->session->data['attributes']);
$this->load->model('catalog/product');
$this->load->model('tool/image');
$productData=$this->model\u catalog\u product->getProductAllImage($this->request->get['catalogno']);
//$result=$this->create_-zip($productData,'my-archive.zip');
$zip=新的ZipArchive;
$zip_name=“image/Catalog”。$this->request->get['catalogno'].“.zip”;
如果($zip->open($zip\u name,ZipArchive::CREATE)){
foreach($productData作为$key=>$image)
{
$filename=substr(strrchr($image['image'],“/”),1);
$zip->addFile(“image/”$image['image'],$filename);
}
$zip->addFile(“图像/目录”。$this->request->get['catalogno']..”.html、“目录”。$this->request->get['catalogno'..”.html”);
$zip->addFile(“image/”$this->request->get['catalogno']..csv“,$this->request->get['catalogno'..csv”);
$zip->close();
标题($_服务器['SERVER_协议'.'200OK');
标题(“内容类型:应用程序
header('Content-Type: text/csv;');
header("Content-Type: application/zip");
header("Content-Transfer-Encoding: Binary");