What can be the matter: when creating an archive (from one file) an empty zip is created. If you feed him the path to a file that does not exist, the archive is not created at all, which is logical. If the path is specified from the root of the home directory /home/www/citename/files/date/file.ext
, an empty zip appears. If you specify the path relative to the root of the site /files/date/file.ext
, the matryoshka from the directories appears in the archive, at the end of which there is the necessary file. What's my mistake?
<?php $zipArchiveName = $fileName .".zip"; $zip = new ZipArchive(); $archive = $tempFolder . "/" . $zipArchiveName; if ($zip->open($archive, ZipArchive::CREATE)!==TRUE) { return; } if( !$zip->addFile( $filePath ) ){ return; } $zip->close();