PHP Create Zip fileWe will make zip yyyymmdd_myfilename.txt as yyyymmdd_myfilename.zip below.
$exportfname = date("Ymd")."_myfilename.txt"; $exportzname = str_replace(".txt", ".zip", $exportfname); if (file_exists($exportzname)) unlink($exportzname); $zip = new ZipArchive(); $filename = "./$exportzname"; if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) die("cannot open $filename\n"); $zip->addFile("./$exportfname","/$exportfname"); $z_n = $zip->numFiles; $z_s = $zip->status; $zip->close(); echo "* numfiles: " . $z_n . "\n"; echo "* status:" . $z_s . "\n"; Tags: php | Related Articles php Calculate Script Duration in PHP and... Generate CSV Spreadsheet with PHP Generate PDFs with PHP Generate XLS Spreadsheet files with ... How to properly escape inline javasc... HTML Table Row Highlight PHP - Resize an Image with GD PHP Calculate Duration of MP3 PHP Create Zip file PHP mail Function With Attachments |