0
I have to generate the zip via an upload via file input, get compressed if not compressed and get it ready for download. It is working, the problem is that if the file sent is zip it compresses again and generates another zip if it is . pdf it compresses and uploads . pdf as well. Why are you duplicating zip file? I would like to resolve this issue.
public function beforeSave($insert)
{
if ($insert) {
date_default_timezone_set('America/Recife');
$this->data = date('d/m/Y');
$this->hora = date('H:i');
$this->dir = str_replace('', '', $this->nome . $_FILES['doc1']['name']);
$zip = new \ZipArchive();
if ($zip->open('../documentos/' . $this->dir . '.zip', \ZipArchive::CREATE) === TRUE) {
foreach ($_FILES as $key => $file) {
if ($file['name']) {
$zip->addFile($file['tmp_name'], $file['name']);
}
}
$zip->close();
$nome = $this->dir;
move_uploaded_file($_FILES['doc1']['tmp_name'], '../documentos/' . $nome);
Yii::$app->session->setFlash('success', "Documentos registrados com sucesso.");
return true;
}
}
}
}
Well, apparently in the code you create the Zip file and add all the upload files without checking the mimetype, so even though it is already a Zip it will add. Do a mime check to see if it’s already Zip or not.
– Woss
But Anderson, why is he moving two to the directory. /documents?
– silvio santos
As for the content all right, the problem is that it is sending two zips files to the directory. If Atachar um arquivo exemplo1.zip ele enviar exemplo1.zip e outro exemplo1.zip.
– silvio santos