Re: problem in creating Zip file [message #178820 is a reply to message #178808] |
Thu, 09 August 2012 05:09 |
J.O. Aho
Messages: 194 Registered: September 2010
Karma:
|
Senior Member |
|
|
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...
>
> <?php
>
> 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
|
|
|