How to create a dynamic zip file in php?

Experts,

I want to allow my users to be able to download several reports at once via a zip file.

I've built a table which displays each db record and provides a link to the report file (.xls) for each record.  The table also has unique checkboxes for each record.  I want users to be able to check the checkboxes and download these .xls reports in a zip file.

My form processes successfully, and the query I have created to look up each record based on the checkboxes marked works.  I now need help created the zipped file based on the query results.

Can anyone help me figure this out?

//PULLS THE key VALUES FOR EACH CHECKBOX AND STORES IT IN AN ARRAY
foreach($_POST as $key => $value) {

//STORES THE key VALUE IN $row_number
$row_number = $key;

//PULLS ALL INFORMATION FROM EACH RECORD BASED ON THE unique id VALUE OF EACH CHECKBOX
$sql="SELECT * FROM permmed_reports WHERE id='$row_number'";
$data = mysql_query($sql);

while($result = mysql_fetch_assoc($data)){

//THE EXACT LOCATION OF THE REPORT FILE (.xls) ON THE SERVER
//BASED ON THE CHECKBOXES SELECTED, THIS WOULD BE THIS REPORT SHOULD BE ADDED TO THE ZIP FILE
$selected_file = 'reports/'.$result['Year'].'/'.$result['Department'].'/'.$result['Site'].'/'.$result['File'].'';

}//END WHILE LOOP

}//END FOREACH LOOP
evibesmusicAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gr8gonzoConsultantCommented:
Just use the PECL zip package:
http://pecl.php.net/package/zip

Here's an article talking about how to use it:
http://devzone.zend.com/article/2105
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
evibesmusicAuthor Commented:
Ok, i installed the dll and found a class that works for this purpose but, I've ran into an issue.

I can get this code to work fine if I navigate directly to


zip.class.php
0
evibesmusicAuthor Commented:
@gr8gonzo:

I am using the class above after installing the correct dll.  I am receiving a weird error though.

When I submit my form, i call the following address: find.php?cmd=zip
I use the following code to call the class and load the files that were accepted dynamically from the form:

if($_GET['cmd']=="zip"){
      include "zip.class.php"; // Get the zipfile class
      $zipfile = new zipfile; // Create an object
      $zipfile->create_dir("."); // Add a subdirectory - must be done.  If a subdirectory is not wanted, just simply add one named "." as shown here
      
      foreach($_POST as $key => $value) {
      
            $id = $key;
            $sql="SELECT * FROM permmed_reports WHERE id='$id'";
            $data = mysql_query($sql);
            
            while($result = mysql_fetch_assoc($data)){
            // Add the data of the file that is wanted, and the full path to it in the zip.
            $zipfile->create_file(file_get_contents('reports/'.$result['Year'].'/'.$result['Department'].'/'.$result['Site'].'/'.$result['File'].''), ''.$result['File'].'');
            }//END WHILE LOOP

      }//END FOREACH LOOP
      
      // Allow user to download file
      header("Content-type: application/zip");
      header("Content-disposition: attachment;filename=\"zip.zip\"");
      echo $zipfile->zipped_file();
}//IF STATEMENT

When this happens I can tell that the form data is being passed but, the class is having a hard time processing the info (i guess?).  I get nothing but symbols but, at the very end I see the variable names being passed correctly.

Anyone have any thoughts?


PK ¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿.¿¿¿¿¿¿¿¿¿¿¿¿PK¿¿¿¿¿¿¿¿3Ç»j¿¿¿6¿¿¿¿¿ANT-AddictionMed-March-10.xlsí[]hUþfö7&&“4mÚÚ.ãFiþ“T¶­Òn+ŠCKiÁhܦ[Ò&ºY!‚ઠ¾DP"èCÀöM)øCA_D’A„`©öA}IÅßDQ°Ðf<çÌ;³MBR¬Òx¾áÜ{çœ{î9sçÎÝ{îÌ^ü¦~áÜ'[¯ ûÁ¢S…x€gmñO,Üq¸è盉Åm…ª$ÝÈxßnžOÌÍR1\‰£s”?õã9$€‰îÌÞL×^û_ÁÃâCÎ`fiàí3â4þL•3”ÖÒ8dIƒ¤$ýHê~.é>’LàuLyþþ=ÞØ=föJ½7$MKZK©ÏDçátc+¾âqüò›†(>3BÃÈáÔ-–ž]VšŠnCMäö=éæŽæ殁Öû[ü“þÖTônzR·…äOÊŸx:\)M·q{¹RgW¸:çZ;¤î©¨UÑšWu7ÚÐ0¿Íö-{§ý-žaŸ‘Þ™iï¿©v¢•R ê…•*4²èÀac®oa{âZÀd6[n"ƒvêé²Q_ÿå Í4ÊMùÓ±óá¬Í|Ãçÿ±:¾¹F>þ‡|6Êðû³Ý­ÿW%¿u~Ç2ü¶eøU7ð§Í(¬RÄá¼¾—¼¡•|C)!9J¼±sž•™d’æ•ù·Çá¡|¾ØÍœïâNs~L8»¦%ÌI"zþ¾0pE$“‰Ê}³ÑË/ÝA‰;™[¡É¼Ú´Ä$¹q§L{5”ž@”ëeøYdàÚ¿]:x¼/; ü6á·KúªpJ—îåË'Ç^!É\´Ñsç5©}FÒs<“P CŽhÀ…l9?"—³aì7ð©t[o€»|Ž¸EÃcýJ½Ãn*­¶¦·Y7à–tÃtrÝwƒB¡P(ŠJ,:@LV­aðoéÂä{¿_}rÈ:ÿVí;.|ßE¼³D OÞKÄ?âñ2à8"†ˆjÀc^\ÐZ£ï±¥ŸI)åéx› KžóRåàð`al|ìdÑ>01˜?%6K÷eŠ™‹_\FÓõ\Žüó]£P( …B¡P( źÁJñ¿yyþòLç]Öô;ÿw\ýãÿ_ˆªÜ˜—ßåóg«üÅ%GËü¿Žõù+:“9fçø?Ì«óäõpßùsœïòDZ~“'¿N´øßþÅA±aŒŽ"lÀ(弸¦ñ³ 1Ão‹Ç‘t÷’f]ñ£Kéøÿb%ëŒà¸ø1²&ÛŒ˜FðzV­è}Ãa¼€ÓtääÚ§^8)>1§ˆa*®ÐLÙçgˆŸŸÕÚO†ì?BŇ¼Üµù³ç&®ß Øÿ3Ç»j¿¿¿6¿¿PK¿¿¿¿¿¿¿¿˜·3²j¿¿¿6¿¿¿¿¿ANT-AddictionMed-Feb-10.xlsí[]hUþföobb2IÓ¦­í²n”æϘ¤eÛ*íF±¢H1´”ŒÆmº%!m¢›-DºÕ_"(ô!`û¦¬"´/"Ƀ B0Tû ¾¤âƒo¢(¨YÏ93ÃÎl“QÏ7œ{ïœsÏ=gîܹ{ϝٹ¯kç/²ýÊp!,+õñ¢mÞ‰ ’‹\ôò­DEÅ]… ‹nd4‚o¶ÎÆf¦©nÁÄÇáJ‰zñbÀXgjªcâ_ÁãâCÆ`¦ià0¢4þL•S”VÓ8dI¤›$½*u?“ô¿IÆð&Ž½¼gŸ;vO˜ÝRïMI“’VSjàºè|/œNlÇ—<ŽÏ¿eˆâã1ä0ˆά³ôÒ²Òxx"h ·H6¶56vô5?ÚÛäô6ÇÃ÷Ó“º# îHöÔóÁJIº;K•Ú;‚íÐ9×Ú‹º§¬VYknÕ½hAÐÇü–„gÙ=ímr {ŒäCI‘v÷‘j;šé U¿^P©L#6<4æø´'®ùL¦Ó¥&Rh¥ž.õôïP.ÓœG½Ü”?Š ß|8`¾áñ_ß\#ÿC¾Jðú³Õ©ÿg9¿y~Û2ü–eøwð'Í0ìB¨Èym!*y]!,ù¦BLr y}!R|Qf’qšWf#ÜBG²Ù|'s¾ú8]Ìù!æãìž@˜|00cXDôü}nà6=ŠŠ4B,ô[›‰J}³ÙÍoÜC‰3™ÛÉ¼Ò´áÇ8¹q¯L{U”žB”keøÙdàö‡¿Þ8|²'Ý'üá·Júšp >—äË'Ç.d&\ïºóºÔ¾(éežI¨†!GØçÇ|º”“KƒY šu¸&ÝÖíãî$ŸCNÑpY¿P/F°—J«í†‰Ø]Ö X—n˜´6|7( …B¡(ÇbˆÈª5þ-ÿ·…gì+o[hÝõéwÄ»DsåÝDü#þ/N€#r`€¨ ¼0æÅ­µÀ1:ð[ú‰”⮎»©°ä9/UöçFFGNç‡Æú³gÄfááT>5÷•!å…¹«\­Cß( …B¡P( …B±Q°RüoÞœ½9Õ~Ÿ=ù.Åÿmqüÿ3Q…+ï!ª÷7å‰*‰^…»_„÷sü¿…è8ûSpö¾@p?€_<“Íæ=ÙÜÙÌpv8Ÿ%Çöl«”¶áÚX*ÛN]ÞŸpÞ»•Š]¥ânTَḫ||$74Ê¢QÑ×½…B¡P( …B¡Pl4Hœ'æåwùüÙ*qÉÑ2ÿ¯ƒc}þŠŽÃdŽÙ9~çój\y-œwþç{Ÿüq¬ßàÊÿ"Züoÿâ XG0BG Â0å9¼²¦ñ³Ãk‹ÇQÂrö’¦ñ“Kéxÿb'ë9á¤ø1´&ÛŒ:˜†ÿzV­è~ÁQœÃY:2ríOS/œŸ˜“Ç •‡Wh¦‰ìó3ÄÏÏjí[ûO…~ñ!+w`mþìû×oûìÿ ˜·3²j¿¿¿6¿¿PK¿¿¿¿¿¿¿¿ïÛÄi¿¿¿6¿¿¿¿¿ANT-AddictionMed-Jan-10.xlsí[]hUþfö7&&“4mÚÚ.ãFiþŒI*ÛVI7ŠEŠ¡¥´`4nÓ) iݬApÕ_"(ô!`û¦TüAБäA!Xª}P_RñÁ7Q,Ԭ眙ag¶IH„(çνwιçž3wîܽçÎ쥯ë/|´ó**p,•ªð¢þ‰’—J\ôóíD%ÅM…ª$ÝÈxßl_HÌÏQ1\…‰£ó”? ài$€Éî́L×û_ÁâCÎ`æhàõq&ÊYJki²¤AÒ-’~ u?“´—$“xÓÇž¹g¿7vO˜}RïUIÓ’ÖRjàSÑù^8Ý؉/y¿ðš!ŠOÆŒû‘Çr8³ÁÒó+JSÑ]ˆ¡‰Ü¾#ÝÜÑÜÜ5Øzß@‹2КŠÞNOꮐüñ#Ω'•Òtw—+uv…Û¡s®µI꞊Z­yU÷¡ =À óÛlß²w:Ðâöé»Ò"í$ÕN´ÒAªA½°R…F¸7lÌõ-lO\˜ÌfËMdÐN=]6êëß \¡¹ˆF¹)”ìÀ|8g3ßðù¿¯o®“ÿ!߀2üþlwëÿYÉo]ß±¿m~Õ ü3 «)q^_ŒKÞPŒJ¾¥˜EHÞXŒ•ž’™dŠæ•…·ÇÑaÇ)t3çÛx€ÓÃœÎÞiDÉóF’ˆž¿Ï \§GÑG‰FHCÉ­Då¾Ùêå—o¡ÄÌ­Ðd^mZbŠÜ¸U¦½JO¡NÊõ2ü,2pýÝ_/>ÙŸ~›ðÛ%}I8Å€Kwòå“c/’d>Úè¹ó²Ô>'éžI¨†!G4àÇb¶œ“KƒY‹0š øDº­/ÀÝM>GÜ¢á±~¡^Œa•ÖÚ Ó‰›¬°!Ý0“ÜôÝ P( …¢K% &«Ö0ø·tqêíß®=6l]|=‰ö=×E¼óD OÞGÄ?âñ2à8"†‰jÀc^\ÐZ£o±¥ŸH)åéx› ËžóRåðÈP~|bütÁ>49䜛Ż3…Ì¥¯)ç{ßãrdúF¡P( …B¡P(ŠÍ‚ÕâóÊ•ÙÎÛ¬™7)þï¸ö>Çÿ?Uyò~¢:¸qQ¨šèy¸±û9¸q?ÇÿÛˆÞ€»0wà„÷ø•Á£¹‘ 'o÷;ù³¹1g¬àcûwvTKÛðl,—§,·.ïO¸ïÝÊÅžrq/j,×pÊS>>ž`Ñ„èë^‚B¡P( …B¡P(6$·óò»|þl•¿¸äh™ÿ×Á±>EÇa2Çì¿ó‡yuž¼î;ŽóýOþ8Öoòä-ý·qP¬‚#§£¿‡0FyÏ­külCÌðÛâqd'ݽ¤9WüÐr:þÿ…ÇÉz£8)~Œ®Ë6£¦¼ž5+zßÁÆpÏâ,9¹öG¨N‹OÌ)`„Êc«4ÓBöùâçg­ö“!û’…!ñÁ‘;°>öÿƒë·öÿïÛÄi¿¿¿6¿¿PK¿¿¿¿¿¿¿¿YW¢j¿¿¿6¿¿¿¿¿ANT-AddictionMed-Feb-09.xlsí[]hUþfö7&&“4mÚÚ.ã¦Òü“´l[¥Ý(¶(R-¥£q›nIH›èf…‚«6øA‰ Û7¥àB}É>¥,­}P_RñÁ7Q,Ԭ眙ag¶IH„(çνwιçž3wîܽçÎìÕoêç/|¶õ&*p¿!,”ªõñ¢-Þ‰’—J\ôòÍD%Å]…ª8ÝÈh×7ÏÅŠ³T7aâÓp‘RàG¢~¼€0ѝڗêÚgÿ+xL|ÈìÃ, ¼ýF”ÆŸI£r†ÒZ‡,itƒ¤ŸHÝ/%ÝO’ ¼‰©c/îÞëŽÝf¯Ô{KÒ¤¤µ”øBt¾N7¶â2ãWß6Dñ¹ˆñ(rFgÖXz~Ii"¼ 4‘Û;’ÍÍÍ]­ô·x'ý­‰ðýô¤nÈŸ9’=õl°R’nãör¥Î®`;tεv"NÝSQ«¢5·ê´¡`~›íYvOû[\Ã#ù`R¤½¤Ú‰V:HÕ¯TªÐH£9¾í‰k>“ét¹‰Ú©§ËF=ý;”+4çÑ(7叒í›gmæÿ÷•ñÍUòñ?ä°Q†×ŸíNý?+ù­Kð;–à·-Á¯ºƒ?m†aB%ÎëQÉ aÉ7b’£¿É‘Òó2“LÒ¼2á¢8:”Íæ»™ómÔÇéaÎ1g×Â䃁¢'¢çï+·éQôP¢Ç`|#Q¹o6ºùµ{(q&s+0™W›ü˜$7î•i¯†ÒS¨“r½?‹Üþè×k‡Oö¥„ß&üvI_NÁçÒ|ùäØk$)†]wސÚç$½À3 Õ0äûü˜O—ócri0kij—¤Ûz}ÜíäsÈ).ëêÅöPi¥Ý0»ËºkÒ Óñuß …B¡P(*±P"²j ‚Kç'?øíÖÓCÖÅwâhßùùw]Ä;Oså½Dü#þ/N€#r`ˆ¨¼0æÅ­µÀ1:ð>[ú‰”®Ž»©°è9/UæÆÆÇNç탃Ù3b³ðP*ŸºzŐrq÷4—CkÐ7 …B¡P( …B¡P¬,ÿ›7ænÌtÞgM¿GñÇ­9þÿ™¨Ê•÷ÕÁ‰û›ˆòDÕD¯À‰ÝÏÁ‰û9þßDô.œý€8û_#¸À¯žÊgsv_6w63šÍg‰Ç±ý‡[ª¥m¸6Ë–S—÷'œ÷nåbO¹¸5–c8á*ˍŒ³h\ôu/A¡P( …B¡P(ë çÉyù]>¶Ê_\r´ÌÿëàXŸ¿¢ã0™cvŽßùü:W^ç?ÇùÞ'ë7¹ò¿ˆþÛ¿8(–ÁŒÑ‘‡ƒ¥<‡—W5~6!bxmñ8²ãÎ^Ò¬#>´˜Ž÷!Æq²žÃNŠ#«²Íh€iø¯gÅŠîw°ÅK8KGF®ýIê…Óâsò¦òè2Í´}~†øùY©ýxÀþãdaP|ÈÊX?{ÿÁõ[>ûYW¢j¿¿¿6¿¿PK¿¿¿¿¿¿¿¿Š½¢Óe¿¿¿6¿¿¿¿¿ANT-AddictionMed-Jan-09.xlsí[]hUþfö7&&“4mÚÚ.ëFiþŒI*ÛVi7Š(†–҂ѸM§&¤ÝèfWmñ%‚RAÚQ«ú¢’<"K¥ú”Š¾‰¢`¡f<çÌ;³MBV¬Òx¾áÜ{çœ{î9sçÎÝ{îÌ^ø¦yáìG›/£ {Á¢S‡x€gmòO,Üq¸èç‰Å …º$ÝÈxßn<Ÿ˜Ÿ£b¸Fç)~ ÆÓH¿ÓýÙ]Ù¾]é÷‰yƒ}˜£·ÛˆÓø3iTÎRÚHã%-’®“ôœÔýLÒÝ$™Æ˘9øÌ];½±{Ø”z¯Hš‘´‘RŸŠÎ÷ÂéÇf|ÅãøùW Q|"fÜ‹"Æ‘Çñë(ME· †6rì¶L{O{{ßHç=ÃþÉpg*z+=‹[BòÇöÛGWÊЍÚZ©ÔÛn‡Î¹Ö6$©ªjUµæU݁.¿#ÌïJû–½ÓáÏ°ÏÈÜ‘éà©ö¢“R ê…•ª4rèÁÝac®oa{âZÀd.Wi"‹nêéŠQ_ÿå*Í´ÊMùÝIf¼¹4ó ŸÿÛêøf|üùÒ¨ÀïÏn·þÕüÎeø=Ëð»–á×]Ã?cFa•#çÍå¸ä-å¨äëÊ ÉQ†ä­å˜ó¤Ì§iæ8ãâ80fÛ¥~æ|p˜óy"ÀÙ>ƒ(ù``ÞHÑó÷…«ô(úph„$1š\OTé›õ^~ñ&JÜéÚ M×õ¦… ž"7n–‰­Ò£h’r³?‹\}ï—‹ûŽåF„ß%ünI_N9àÒí|ùäØ$™¶zî¼$µOIz–gªaÈ ø±«äåÒ`6"Œ=f‹×mƒîVò9⠏õ³¬Dv­¶ ‰¬p]ºádrÍwƒB¡P(ŠÚ°è¿1YÓ†Á¿´§ßúõÊ£cÖû¯%ѽíãïúˆ÷6Q“ñOüƒD¼H8ŽÈ1¢ð²™—À8FÞ$bK?’RÊÓñ6–<ç…̾ñÑâäÔä±Rzïô¨}\l–ïÌ–²¾6¸Œ‡ß™áräŸï…B¡P( …B¡P(ÖVŠÿÍKç/ÍöÞbyƒâÿž+püÿQ'"j‚÷·•ˆê‰žƒ»Ÿ‚÷sü¿èu¸û³p÷¾Dx?€_(<’Ÿ²‹é!»x"_°%›xÛ¿»©^Ú†gc©Ü˜—ßåóG­ümGËü¿Žõù;“9fçø?ÛkòäÍpßùsœïȱ~›'ÿ“hñ¿ý‹ƒbìÇ$%¤±Ê‹x¶¦ñ³1Ão‹ÇQ:éî%͹â–Òñÿ/Ä8DÖ‹˜Àñc¢&ÛŒ˜FðzV­è}%ÃœÄ :òríQ/Ÿ˜SÂ8•+4ÓAöùâçgµö“!û÷“…QñÁ–;P›?;ÿÆõ[ûŠ½¢Óe¿¿¿6¿¿PK¿¿¿¿¿¿¿¿Š½¢Óe¿¿¿6¿¿¿¿¿ANT-AddictionMed-Jan-Jun-09.xlsí[]hUþfö7&&“4mÚÚ.ëFiþŒI*ÛVi7Š(†–҂ѸM§&¤ÝèfWmñ%‚RAÚQ«ú¢’<"K¥ú”Š¾‰¢`¡f<çÌ;³MBV¬Òx¾áÜ{çœ{î9sçÎÝ{îÌ^ø¦yáìG›/£ {Á¢S‡x€gmòO,Üq¸èç‰Å …º$ÝÈxßn<Ÿ˜Ÿ£b¸Fç)~ ÆÓH¿ÓýÙ]Ù¾]é÷‰yƒ}˜£·ÛˆÓø3iTÎRÚHã%-’®“ôœÔýLÒÝ$™Æ˘9øÌ];½±{Ø”z¯Hš‘´‘RŸŠÎ÷ÂéÇf|ÅãøùW Q|"fÜ‹"Æ‘Çñë(ME· †6rì¶L{O{{ßHç=ÃþÉpg*z+=‹[BòÇöÛGWÊЍÚZ©ÔÛn‡Î¹Ö6$©ªjUµæU݁.¿#ÌïJû–½ÓáÏ°ÏÈÜ‘éà©ö¢“R ê…•ª4rèÁÝac®oa{âZÀd.Wi"‹nêéŠQ_ÿå*Í´ÊMùÝIf¼¹4ó ŸÿÛêøf|üùÒ¨ÀïÏn·þÕüÎeø=Ëð»–á×]Ã?cFa•#çÍå¸ä-å¨äëÊ ÉQ†ä­å˜ó¤Ì§iæ8ãâ80fÛ¥~æ|p˜óy"ÀÙ>ƒ(ù``ÞHÑó÷…«ô(úph„$1š\OTé›õ^~ñ&JÜéÚ M×õ¦… ž"7n–‰­Ò£h’r³?‹\}ï—‹ûŽåF„ß%ünI_N9àÒí|ùäØ$™¶zî¼$µOIz–gªaÈ ø±«äåÒ`6"Œ=f‹×mƒîVò9⠏õ³¬Dv­¶ ‰¬p]ºádrÍwƒB¡P(ŠÚ°è¿1YÓ†Á¿´§ßúõÊ£cÖû¯%ѽíãïúˆ÷6Q“ñOüƒD¼H8ŽÈ1¢ð²™—À8FÞ$bK?’RÊÓñ6–<ç…̾ñÑâäÔä±Rzïô¨}\l–ïÌ–²¾6¸Œ‡ß™áräŸï…B¡P( …B¡P(ÖVŠÿÍKç/ÍöÞbyƒâÿž+püÿQ'"j‚÷·•ˆê‰žƒ»Ÿ‚÷sü¿èu¸û³p÷¾Dx?€_(<’Ÿ²‹é!»x"_°%›xÛ¿»©^Ú†gc©Ü˜—ßåóG­ümGËü¿Žõù;“9fçø?ÛkòäÍpßùsœïȱ~›'ÿ“hñ¿ý‹ƒbìÇ$%¤±Ê‹x¶¦ñ³1Ão‹ÇQ:éî%͹â–Òñÿ/Ä8DÖ‹˜Àñc¢&ÛŒ˜FðzV­è}%ÃœÄ :òríQ/Ÿ˜SÂ8•+4ÓAöùâçgµö“!û÷“…QñÁ–;P›?;ÿÆõ[ûŠ½¢Óe¿¿¿6¿¿PK¿¿¿¿¿¿¿¿YW¢j¿¿¿6¿¿¿¿¿ANT-AddictionMed-Jul-Dec-09.xlsí[]hUþfö7&&“4mÚÚ.ã¦Òü“´l[¥Ý(¶(R-¥£q›nIH›èf…‚«6øA‰ Û7¥àB}É>¥,­}P_RñÁ7Q,Ԭ眙ag¶IH„(çνwιçž3wîܽçÎìÕoêç/|¶õ&*p¿!,”ªõñ¢-Þ‰’—J\ôòÍD%Å]…ª8ÝÈh×7ÏÅŠ³T7aâÓp‘RàG¢~¼€0ѝڗêÚgÿ+xL|ÈìÃ, ¼ýF”ÆŸI£r†ÒZ‡,itƒ¤ŸHÝ/%ÝO’ ¼‰©c/îÞëŽÝf¯Ô{KÒ¤¤µ”øBt¾N7¶â2ãWß6Dñ¹ˆñ(rFgÖXz~Ii"¼ 4‘Û;’ÍÍÍ]­ô·x'ý­‰ðýô¤nÈŸ9’=õl°R’nãör¥Î®`;tεv"NÝSQ«¢5·ê´¡`~›íYvOû[\Ã#ù`R¤½¤Ú‰V:HÕ¯TªÐH£9¾í‰k>“ét¹‰Ú©§ËF=ý;”+4çÑ(7叒í›gmæÿ÷•ñÍUòñ?ä°Q†×ŸíNý?+ù­Kð;–à·-Á¯ºƒ?m†aB%ÎëQÉ aÉ7b’£¿É‘Òó2“LÒ¼2á¢8:”Íæ»™ómÔÇéaÎ1g×Â䃁¢'¢çï+·éQôP¢Ç`|#Q¹o6ºùµ{(q&s+0™W›ü˜$7î•i¯†ÒS¨“r½?‹Üþè×k‡Oö¥„ß&üvI_NÁçÒ|ùäØk$)†]wސÚç$½À3 Õ0äûü˜O—ócri0kij—¤Ûz}ÜíäsÈ).ëêÅöPi¥Ý0»ËºkÒ Óñuß …B¡P(*±P"²j ‚Kç'?øíÖÓCÖÅwâhßùùw]Ä;Oså½Dü#þ/N€#r`ˆ¨¼0æÅ­µÀ1:ð>[ú‰”®Ž»©°è9/UæÆÆÇNç탃Ù3b³ðP*ŸºzŐrq÷4—CkÐ7 …B¡P( …B¡P¬,ÿ›7ænÌtÞgM¿GñÇ­9þÿ™¨Ê•÷ÕÁ‰û›ˆòDÕD¯À‰ÝÏÁ‰û9þßDô.œý€8û_#¸À¯žÊgsv_6w63šÍg‰Ç±ý‡[ª¥m¸6Ë–S—÷'œ÷nåbO¹¸5–c8á*ˍŒ³h\ôu/A¡P( …B¡P(ë çÉyù]>¶Ê_\r´ÌÿëàXŸ¿¢ã0™cvŽßùü:W^ç?ÇùÞ'ë7¹ò¿ˆþÛ¿8(–ÁŒÑ‘‡ƒ¥<‡—W5~6!bxmñ8²ãÎ^Ò¬#>´˜Ž÷!Æq²žÃNŠ#«²Íh€iø¯gÅŠîw°ÅK8KGF®ýIê…Óâsò¦òè2Í´}~†øùY©ýxÀþãdaP|ÈÊX?{ÿÁõ[>ûYW¢j¿¿¿6¿¿PK¿¿ ¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿.PK¿¿¿¿¿¿¿¿¿¿3Ç»j¿¿¿6¿¿¿¿¿¿¿¿¿¿¿ ¿¿¿+¿¿¿ANT-AddictionMed-March-10.xlsPK¿¿¿¿¿¿¿¿¿¿˜·3²j¿¿¿6¿¿¿¿¿¿¿¿¿¿¿ ¿¿¿Ü¿¿ANT-AddictionMed-Feb-10.xlsPK¿¿¿¿¿¿¿¿¿¿ïÛÄi¿¿¿6¿¿¿¿¿¿¿¿¿¿¿ ¿¿¿‹ ¿¿ANT-AddictionMed-Jan-10.xlsPK¿¿¿¿¿¿¿¿¿¿YW¢j¿¿¿6¿¿¿¿¿¿¿¿¿¿¿ ¿¿¿9¿¿ANT-AddictionMed-Feb-09.xlsPK¿¿¿¿¿¿¿¿¿¿Š½¢Óe¿¿¿6¿¿¿¿¿¿¿¿¿¿¿ ¿¿¿è¿¿ANT-AddictionMed-Jan-09.xlsPK¿¿¿¿¿¿¿¿¿¿Š½¢Óe¿¿¿6¿¿¿¿¿¿¿¿¿¿¿ ¿¿¿’¿¿ANT-AddictionMed-Jan-Jun-09.xlsPK¿¿¿¿¿¿¿¿¿¿YW¢j¿¿¿6¿¿¿¿¿¿¿¿¿¿¿ ¿¿¿@¿¿ANT-AddictionMed-Jul-Dec-09.xlsPK¿¿¿¿¿¿8¿¿ó ¿¿¿¿

Open in new window

0
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

evibesmusicAuthor Commented:
A picture is worth a thousand words...shows the error...
screen-shot.jpg
0
gr8gonzoConsultantCommented:
That's the right data - you're looking at a ZIP file. You just need to pass the right headers. Check out the PHP documentation page for the header() function - there are examples of how to prompt download popups.
0
evibesmusicAuthor Commented:
@gr8gonzo:

The odd thing is that, if I take the following code and create a new page called 'test.php' and run it, it produces the zip file and prompts for download but, none of my dynamically called files are inside the archive because the variables are not being passed to test.php.

If I take the code and create the following 'test.php' page, is there a way that I can pass the values of the checkboxes to it?  I believe that would fix the problem.

test.php:

 include "zip.class.php"; // Get the zipfile class
      $zipfile = new zipfile; // Create an object
      $zipfile->create_dir("."); // Add a subdirectory - must be done.  If a subdirectory is not wanted, just simply add one named "." as shown here
     
//I NEED TO GET THE VALUES THAT WERE POSTED FROM THE FORM BUT, DON'T KNOW HOW TO PROPERLY STORE AND THEN PASS THEM SO THAT THEY CAN BE USED ON THIS PAGE
      foreach($_POST as $key => $value) {
     
            $id = $key;
            $sql="SELECT * FROM permmed_reports WHERE id='$id'";
            $data = mysql_query($sql);
           
            while($result = mysql_fetch_assoc($data)){
            // Add the data of the file that is wanted, and the full path to it in the zip.
            $zipfile->create_file(file_get_contents('reports/'.$result['Year'].'/'.$result['Department'].'/'.$result['Site'].'/'.$result['File'].''), ''.$result['File'].'');
            }//END WHILE LOOP

      }//END FOREACH LOOP
     
      // Allow user to download file
      header("Content-type: application/zip");
      header("Content-disposition: attachment;filename=\"zip.zip\"");
      echo $zipfile->zipped_file();

0
gr8gonzoConsultantCommented:
Can you post the final HTML code for the form?
0
evibesmusicAuthor Commented:
Please see the attached source code of the compiled html page which produces my forms code.

You will notice that each row is printed with a checkbox which has a unique name attribute.  The value of the each name attribute is the 'id' stored in the database for this entry.  These values need to be passed to the code listed above to dynamically add the files to the zipped archive.
<form action="find.php?cmd=zip" method="post" enctype="multipart/form-data" name="zip">
				<table width="100%" border="0" cellspacing="2" cellpadding="2">
				  <tr>
					<td style="width:105px;">
					  <div align="center"><a href="download.php?cmd=file&id=9" title="ANT - Addiction Medicine: January, 2010"><img align="center" border="0" src="images/excel_logo.jpg">
						</a>
					  </div>
					</td>
					<td colspan="3"><b>Your search found the following results for:</b><h2>ANT - Addiction Medicine<br />January, 2010</h2><a href="download.php?cmd=file&id=9" 
					title="ANT - Addiction Medicine: January, 2010">Download This File</a>
					</td>
				  </tr><tr><td colspan="4"><hr /></td></tr><tr><td><div align="center"><img align="center" border="0" src="images/excel_logo.jpg"></div></td><td colspan="3"><h2>Related search results for:</h2><b>ANT - Addiction Medicine</b></td></tr>
			<tr>
			<td align="center"><u><b>File Format</u></b></td>
			<td align="center"><u><b>Year</b></u></td>
			<td align="center"><u><b>Report Month or Range</b></u></td>
			<td align="center"><u><b>Zip This File</b></u></td>
			</tr><tr><td><div align="center"><a href="download.php?cmd=file&id=11" title="ANT - Addiction Medicine: March, 2010"><img align="center" border="0" src="images/excel_logo_sm.jpg"></a></div></td><td><div align="center">2010</div></td><td align="center"><a href="download.php?cmd=file&id=11" title="ANT - Addiction Medicine: March, 2010">
						<b>March</b>
						</a></td><td><div align="center"><input name="11" type="checkbox" value="11"></div></td></tr><tr><td></td><td></td><td></td><td></td></tr><tr><td><div align="center"><a href="download.php?cmd=file&id=10" title="ANT - Addiction Medicine: February, 2010"><img align="center" border="0" src="images/excel_logo_sm.jpg"></a></div></td><td><div align="center">2010</div></td><td align="center"><a href="download.php?cmd=file&id=10" title="ANT - Addiction Medicine: February, 2010">
						<b>February</b>
						</a></td><td><div align="center"><input name="10" type="checkbox" value="10"></div></td></tr><tr><td></td><td></td><td></td><td></td></tr><tr><td><div align="center"><a href="download.php?cmd=file&id=9" title="ANT - Addiction Medicine: January, 2010"><img align="center" border="0" src="images/excel_logo_sm.jpg"></a></div></td><td><div align="center">2010</div></td><td align="center"><a href="download.php?cmd=file&id=9" title="ANT - Addiction Medicine: January, 2010">
						<b>January</b>
						</a></td><td><div align="center"><input name="9" type="checkbox" value="9"></div></td></tr><tr><td></td><td></td><td></td><td></td></tr><tr><td><div align="center"><a href="download.php?cmd=file&id=16" title="ANT - Addiction Medicine: February, 2009"><img align="center" border="0" src="images/excel_logo_sm.jpg"></a></div></td><td><div align="center">2009</div></td><td align="center"><a href="download.php?cmd=file&id=16" title="ANT - Addiction Medicine: February, 2009">
						<b>February</b>
						</a></td><td><div align="center"><input name="16" type="checkbox" value="16"></div></td></tr><tr><td></td><td></td><td></td><td></td></tr><tr><td><div align="center"><a href="download.php?cmd=file&id=15" title="ANT - Addiction Medicine: January, 2009"><img align="center" border="0" src="images/excel_logo_sm.jpg"></a></div></td><td><div align="center">2009</div></td><td align="center"><a href="download.php?cmd=file&id=15" title="ANT - Addiction Medicine: January, 2009">
						<b>January</b>
						</a></td><td><div align="center"><input name="15" type="checkbox" value="15"></div></td></tr><tr><td></td><td></td><td></td><td></td></tr><tr><td><div align="center"> <a href="download.php?cmd=file&id=18" title="ANT - Addiction Medicine: Jan-Jun, 2009"><img align="center" border="0" src="images/excel_logo_sm.jpg"></a></div></td><td><div align="center">2009</div></td><td align="center"><a href="download.php?cmd=file&id=18" title="ANT - Addiction Medicine: Jan-Jun, 2009">
						<b>Jan-Jun</b>
						</a></td><td><div align="center"><input name="18" type="checkbox" value="18"></div></td></tr><tr><td></td><td></td><td></td><td></td></tr><tr><td><div align="center"> <a href="download.php?cmd=file&id=19" title="ANT - Addiction Medicine: July-Dec, 2009"><img align="center" border="0" src="images/excel_logo_sm.jpg"></a></div></td><td><div align="center">2009</div></td><td align="center"><a href="download.php?cmd=file&id=19" title="ANT - Addiction Medicine: July-Dec, 2009">
						<b>July-Dec</b>
						</a></td><td><div align="center"><input name="19" type="checkbox" value="19"></div></td></tr><tr><td></td><td></td><td></td><td></td></tr><tr><td colspan="3"></td><td><div align="center"><input name="submit" value="zip" type="submit" /></div></td></tr></table></form>

Open in new window

0
gr8gonzoConsultantCommented:
Try changing the names of your checkboxes to use an array:

Example:

From:
<input name="18" type="checkbox" value="18">

To:
<input name="reports[]" type="checkbox" value="18">

Then on the next page, just loop through $_POST["reports"] like this:

foreach($_POST["reports"] as $reportID)
{
   // query using the $reportID variable
}
0
evibesmusicAuthor Commented:
I am creating the table dynamically, so my original code looked like this:

<input name="'.$result2['id'].'" type="checkbox" value="'.$result2['id'].'">

Should the code you are suggesting look like this then:

<input name="'.reports[].'" type="checkbox" value="'.$result2['id'].'">
0
evibesmusicAuthor Commented:
Made the changes.  The variables are still being passed using the code you suggested. Still getting the same error using the following updated code:

//CHANGED MY FORM CODE TO
<input name="reports[]"  type="checkbox" value="'.$result2['id'].'">

if($_GET['cmd']=="zip"){
      include "zip.class.php"; // Get the zipfile class
      $zipfile = new zipfile; // Create an object
      $zipfile->create_dir("."); // Add a subdirectory - must be done.  If a subdirectory is not wanted, just simply add one named "." as shown here
      
      foreach($_POST["reports"] as $reportID) {
      
            $sql="SELECT * FROM permmed_reports WHERE id='$reportID'";
            $data = mysql_query($sql);
            
            while($result = mysql_fetch_assoc($data)){
            // Add the data of the file that is wanted, and the full path to it in the zip.
            $zipfile->create_file(file_get_contents('reports/'.$result['Year'].'/'.$result['Department'].'/'.$result['Site'].'/'.$result['File'].''), ''.$result['File'].'');
            }//END WHILE LOOP

      }//END FOREACH LOOP
      
      // Allow user to download file
      header("Content-type: application/zip");
      header("Content-disposition: attachment;filename=\"zip.zip\"");
      echo $zipfile->zipped_file();
}//IF STATEMENT
error.jpg
0
evibesmusicAuthor Commented:
SWEET!  Got it to work with your help.  Thank you so much, this has been driving me crazy for a few days now.

Turns out that the only way I could get the selected files to zip up correctly was to call an external file, and not part of the current page such as 'post=find.php?cmd=zip'.

I now direct my form to post the information to 'zipfiles.php', and the zip routine works successfully, using the dynamically selected files given by the user.

So to recap, i used your suggested change to my form's checkboxes as:
<input name="reports[]"  type="checkbox" value="'.$result2['id'].'">

Here is my final code for 'zipfiles.php' which uses your suggested codeing:
<?php
include ('db_connection.php');
require ('zip.class.php'); // Get the zipfile class

$zipfile = new zipfile; // Create an object
$zipfile->create_dir("."); // Add a subdirectory - must be done.  If a subdirectory is not wanted, just simply add one named "." as shown here
      
foreach($_POST[reports] as $reportID) {
      
$sql="SELECT * FROM permmed_reports WHERE id='$reportID'";
$data = mysql_query($sql) or die ("Could not run query: " . $sql . "<br />\n" . mysql_error () );
            
while($result = mysql_fetch_assoc($data)){            
// Add the data of the file that is wanted, and the full path to it in the zip.
$zipfile->create_file(file_get_contents('reports/'.$result['Year'].'/'.$result['Department'].'/'.$result['Site'].'/'.$result['File'].''), ''.$result['File'].'');
}//END WHILE LOOP

}//END FOREACH LOOP
      
// Allow user to download file
header("Content-type: application/zip");
header("Content-disposition: attachment;filename=\"PermMed_Reporting_Bundle.zip\"");
echo $zipfile->zipped_file();
?>
zip.class.php
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.