

<?php



$todaytms = time();

$namefilezip = $idtd . '-' . $todaytms . ".zip";

$namefilezippath = "uploadtddocuments/ziptd/" . $idtd . '-' . $todaytms . ".zip";

$zipnamefile = $namefilezip;



// change path ... name for link on pdf with website address

$namefilezippathpdf = $linkglobal . "public/tduploaddocuments/ziptd/" . $idtd . '-' . $todaytms . ".zip";



$documentlist = new WA_MySQLi_RS("documentlist", $cmctrfdb, 0);

$documentlist->setQuery("SELECT * FROM tdfileattached WHERE tdfileattached.iddata_td='$idtd'");

$documentlist->execute();



$zip = new ZipArchive;



if ($zip->open($namefilezippath, ZipArchive::CREATE) === TRUE) {



    if (!empty($documentlist->getColumnVal("idtdfileattached"))) {





        // Add files to the zip file

        $wa_startindex = 0;

        while (!$documentlist->atEnd()) {

            $wa_startindex = $documentlist->Index;





            $newdocname = $documentlist->getColumnVal("filename_fileattached");

            $pathnewdocname = "uploadtddocuments/" . $newdocname;



            $zip->addFile($pathnewdocname, $newdocname);







            $documentlist->moveNext();

        }

        $documentlist->moveFirst(); //return RS to first record

        unset($wa_startindex);

        unset($wa_repeatcount);

    }

    //  add photos to zip





    // All files are added, so close the zip file.

    $zip->close();

}

?>