Path: csiph.com!usenet.pasdenom.info!news.albasani.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "J.O. Aho" Newsgroups: comp.lang.php Subject: Re: problem in creating Zip file Date: Thu, 09 Aug 2012 07:09:18 +0200 Lines: 71 Message-ID: References: <1592f3dd-f681-4100-b6b4-e1684b06322c@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net zbgYNY6Kk9bIz568WpeDIwEJUwiQymzu2ajO6AApQMB2sy4XTt5gcOf8/mP5F5sM4U Cancel-Lock: sha1:a9apsZe884769DFuWFNu9d1iAiQ= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120613 Firefox/12.0 SeaMonkey/2.9.1 In-Reply-To: <1592f3dd-f681-4100-b6b4-e1684b06322c@googlegroups.com> Xref: csiph.com comp.lang.php:6749 Supriya wrote: > Hi All > i m trying to create a Zip file of 1 folder which contains 2 folders and 33 files but the resulted zip file only contains 21 file and 1 folder.And when i open the files of zip folder it says files r corrupted. > > Here is my code: > Plz help me to find out what is wrong there... > > > include("variable.php"); > > ini_set("max_execution_time", 18000); This will not help you, and as Jerry pointed out you may not be allowed to change the value. Sure, the issue may be that the execution of the script needs more time, but you totally have forgot that there is a timeout in your browser, and when your browser times out, then the script will stop running on the server too and you end up with an unfinished job. > > // create object > > $zip = new ZipArchive(); > > // open archive > > if ($zip->open($outputfoldername . ".zip", ZIPARCHIVE::CREATE) !== TRUE) { > die ("Could not open archive"); > } > > // initialize an iterator > // pass it the directory to be processed > > $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($outputfoldername . "/")); > > // iterate over the directory > // add each file found to the archive > > foreach ($iterator as $key=>$value) { > $zip->addFile(realpath($key), $key) or die ("ERROR: Could not add file: $key"); if you make some output here, then you will extend the life for your connection, unless one iteration takes too long time. > } > > // close and save archive > > $zip->close(); > echo "Archive created successfully."; > ?> If you can, make a cron job of this instead (not many web hotels does offer customers to run cron jobs), the job reads from a database table which jobs it has to do, it takes the oldest one in the list each time it's run (set it to run every 5 or 10 minutes) and marks it to be worked on, so that no other instance will try to do the same time if it takes longer than the time you set between two jobs, and when the process is finished, mark the job as finished (this gives you the possibility to check for jobs which fails, specially if you also set the time when the job changed state). Then in the web ui you just have a way to put jobs into the queue. You get a lot more stable system this way. -- //Aho