ppeasy/public/include/bck040723zipcreation.php

67 lines
1.9 KiB
PHP

<?php
$todaytms=time();
$namefilezip=$idtrf.'-'.$todaytms.".zip";
$namefilezippath="uploaddocuments/zip/".$idtrf.'-'.$todaytms.".zip";
$zipnamefile=$namefilezip;
// change path ... name for link on pdf with website address
$namefilezippathpdf=$linkglobal."public/uploaddocuments/zip/".$idtrf.'-'.$todaytms.".zip";
$documentlist = new WA_MySQLi_RS("documentlist",$cmctrfdb,0);
$documentlist->setQuery("SELECT * FROM fileattached WHERE fileattached.idtrfdetails='$idtrf'");
$documentlist->execute();
$photolist = new WA_MySQLi_RS("photolist",$cmctrfdb,0);
$photolist->setQuery("SELECT * FROM `trf-details` WHERE `trf-details`.idtrfdetails='$idtrf'");
$photolist->execute();
if (!empty($documentlist->getColumnVal("idfileattached"))) {
$zip = new ZipArchive;
if ($zip->open($namefilezippath, ZipArchive::CREATE) === TRUE)
{
// Add files to the zip file
$wa_startindex = 0;
while(!$documentlist->atEnd()) {
$wa_startindex = $documentlist->Index;
$newdocname=$documentlist->getColumnVal("filename_fileattached");
$pathnewdocname="uploaddocuments/".$newdocname;
$zip->addFile($pathnewdocname, $newdocname);
$documentlist->moveNext();
}
$documentlist->moveFirst(); //return RS to first record
unset($wa_startindex);
unset($wa_repeatcount);
// add photos to zip
if (!empty($photolist->getColumnVal("photofilename"))) {
$newdocname=$photolist->getColumnVal("photofilename");
$pathnewdocname="uploaddocuments/".$newdocname;
$zip->addFile($pathnewdocname, $newdocname);
}
if (!empty($photolist->getColumnVal("photoone"))) {
$newdocname=$photolist->getColumnVal("photoone");
$pathnewdocname="uploaddocuments/".$newdocname;
$zip->addFile($pathnewdocname, $newdocname);
}
if (!empty($photolist->getColumnVal("phototwo"))) {
$newdocname=$photolist->getColumnVal("phototwo");
$pathnewdocname="uploaddocuments/".$newdocname;
$zip->addFile($pathnewdocname, $newdocname);
}
// All files are added, so close the zip file.
$zip->close();
}
}
?>