"End-of-central-directory signature not found" after downloading zip file from my website

1.1k views Asked by At

I have a zip file named filename.zip. I used FileZilla to upload it to /home/protected directory on my website, hosted by NearlyFreeSpeech.net.

Recently, when I tried downloading the zip file and opening it by running unzip filename.zip in the terminal, I run into this error:

Archive:  filename.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.
unzip:  cannot find zipfile directory in one of filename.zip or
        filename.zip.zip, and cannot find filename.zip.ZIP, period.

Before last week or so, I could download the file from my website and unzip it without a problem.

I can unzip the file before copying it to my website.

I cannot unzip the copy of the file I download afterward.

Here is the PHP that handles the download.

$file = "path/to/file";

if(file_exists($file)){
    $handle = fopen($file, "r");
    header('Content-Description: File Transfer');
    header('Content-Type: application/zip');
    header('Content-Disposition: attachment; filename="'.basename($file).'"');
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: '.filesize($file));
    ob_clean();
    flush();
    readfile($file);
    fclose($handle);

} else {
    echo('File does not exist');
}

Why can I no longer properly unzip the zip files I downloaded?

0

There are 0 answers