function downloadZipImg public (picAllArr $, $ enterprise_id) { // $ picAllArr = [ // 'https://dss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=2333857494,1212940832&fm=26&gp=0.jpg', // ' https://dss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3808706043,3843571795&fm=26&gp=0.jpg ' //]; $ tmpDir =' ./static/zip/images/ '; // similar / www / public / Upload / (! the file_exists ($ tmpDir)) IF { // Create a folder mkdir ($ tmpDir, 0777, to true); } // zipName = DATE $ ( 'His-') the mt_rand (1000, 9999).. '.zip'; // archive file name $ zipName = $ enterprise_id '.zip' .; . $ zipNameUrl = $ tmpDir $ zipName ; // file path // delete files compressed before unlink ($ zipNameUrl); // delete a file // file generated $ = new new ZIP \ ZipArchive (); IF (zip-$> Open ($ zipNameUrl, \ ZipArchive :: OVERWRITE) ==! to true) { // oVERWRITE parameter overrides the archive file must already exist IF (zip-$> Open ($ zipNameUrl, \ :: ZipArchive the CREATE)! == to true) { // the file does not exist, create a new the files are opened using the additional content files to the CREATE ZIP return 'download fails, the folder does not exist'; } } the foreach ($ $ file picAllArr AS) { // determines whether there is image $ isFile = $ this-> checkFileExists ( $ file ); ! IF ($ isFile) { Continue; } // crawl graphic content file_get_contents fileContent = $ ($ File); // Add image $ File = substr ($ File, 0, -13); $ zip-> AddFromString (the basename ($ File), $ fileContent); } // close $ zip- > use Close (); // no file IF {(file_exists ($ zipNameUrl)!) return 'download failed, the picture does not exist or can not be downloaded'; } // header ( "Cache-Control: public"); // header ( "Content-the Description: file Transfer"); // header ( 'Content-Disposition: Attachment; filename ='. $ zipName); // file name // header ( "Content-Type: application / zip"); // zip format // // header ( "Content-Type :application / octet-stream ' "); // zip format // header ( "Content-Transfer- Encoding: binary"); // tell the browser, which is a binary file // header ( 'Content-Length: '. Filesize ($ zipNameUrl)); // tells the browser, file size // // // the following two steps must be // ob_clean (); // flush (); / / @ ReadFile ($ zipNameUrl); // unlink ($ zipNameUrl); // delete the file return substr ($ zipNameUrl, 2); }