0
When I’m using the method close to close the instance of ZipArchive I’m getting the following error:
Ziparchive::close(): Read error: Is a directory
The code of my application where the close is executed that’s:
$solicitacoes = Remessa::with('solicitacoes')
->findOrFail($id)
->solicitacoes()
->with('usuario')
->get();
$zip = new \ZipArchive();
$zipName = tempnam(sys_get_temp_dir(), 'remessa_');
if ($zip->open($zipName, ZipArchive::CREATE) === true) {
$filesWithProblems = [];
$filesNormal = [];
$dir = public_path('imagens');
$remessaId = zero_fill($id, 4);
foreach ($solicitacoes as $solicitacao) {
if ($solicitacao->usuario->nivel_id == 12) {
$filename = $dir . "/colaboradores/{$solicitacao->usuario->id}/{$solicitacao->foto}";
$filenameInZip = "$remessaId/$solicitacao->foto";
} else {
$filename = $dir . "/{$solicitacao->usuario->matricula}/{$solicitacao->foto}";
$filenameInZip = "$remessaId/$solicitacao->foto";
}
if (file_exists($filename)) {
$zip->addFile($filename, $filenameInZip);
$filesNormal[] = $filename;
} else {
$filesWithProblems[] = $filename;
}
}
}
$zip->close();
I wanted to understand what this message means!
means that it is a directory, what content of the variable
$zipName? The folder where you are writing the zip has the proper write permissions?– Neuber Oliveira
$zipNameis a file in the temporary folder created bytempnam. Only in a specific shipment the problem occurs. In the rest it works normal.– Wallace Maxters
I meant the same content, the string it’s generating, like,
remessa1.zip,nome qualquer.zip. If it is only in a specific shipment maybe it is not some damaged/broken file causing it?– Neuber Oliveira
I found this in a comment in another post:
The message: [PHP Error] ZipArchive::close(): Read error: Is a directory --> the answer is simple, it is just because there was some symbolic link in the file tree– Neuber Oliveira
You just want to add files right? Or folders too, just for a test try to change this
if (file_exists($filename))thereforeif (is_file($filename))– Guilherme Nascimento
I want to add files. Add one by one
– Wallace Maxters