zip and download files using php

前端 未结 7 891
暗喜
暗喜 2021-02-02 03:41

I am trying to zip and download files from a folder named \"upload\". Zip file is downloading but I couldn\'t open (extract) it. I am getting an error like \"The archive is eith

7条回答
  •  死守一世寂寞
    2021-02-02 03:55

    $files = "upload/".array('Dear GP.docx','ecommerce.doc');
    

    Should be:

    $files = array('upload/Dear GP.docx','upload/ecommerce.doc');
    

    If you are still having issues then you should check if you have write permission to the current directory. You can check the return value of close() to check whether the file was actually written.

    $res = $zip->close();
    var_dump($res);
    

    The output should be bool(true) if the write was successful.

    Looks like you have a the wrong var name in the filesize() call also:

    header('Content-Length: ' . filesize($zipfilename));
    

    Should probably be:

    header('Content-Length: ' . filesize($zipname));
    

    You could also add extra validation to check whether the files you are adding to the zip actually exist and before sending check the zip file exists.

    Edit: Turn on display errors to help you debug locally:

    ini_set('display_errors', 1);
    error_reporting(E_ALL);
    

提交回复
热议问题