Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

195
Visualizações
Zip content is cleared after downloading it in php

The Problem is that when downloading the zip, its content gets deleted. I use this code to create the zip and add the files to it:

    $zipName = "full path";
    $zip = new ZipArchive();
    $zip->open($zipName, ZipArchive::CREATE);
    for ($i = 0; $i < $length; $i++) {
        if ($ausgabeArray[$i]["filePath"] != '') {
            $zip->addFromString(basename($ausgabeArray[$i]["filePath"]), file_get_contents($ausgabeArray[$i]["filePath"]));
        }
    }
    $zip->close();
    for ($i = 0; $i < $length; $i++) {
        unlink($ausgabeArray[$i]["filePath"]);
    }

And I use this code to download the zip:

        header("Content-disposition: attachment; filename=" . $name);
        header("Content-type: application/".$endung);
        readfile($path);
        unlink($path);
        //name = basename from the path of the zip
        //path = full path to the zip
        //endung = zip

This worked fine on the old server, but after changing it, it stopped working. I stopped the code once before readfile($path); and viewed the zip in the folder and downloaded it from there, everything worked fine this way, but this is of course no option for anybody who has no permission for the server directories.

We use this server:

  1. Ubuntu 20.04.2 LTS
  2. Apache/2.4.41 (Ubuntu)
  3. 7.3.29 FPM-Application

I'm not sure if the problem has anything to do with the server change or just my code, but I didn't change a thing, and now it is not working any more, so I think it is possible. I hope someone had this problem before and can help me. Thanks!

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda