FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » problem in creating Zip file
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
problem in creating Zip file [message #178808] Wed, 08 August 2012 06:40 Go to next message
Supriya is currently offline  Supriya
Messages: 2
Registered: August 2012
Karma: 0
Junior Member
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);


// 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");
}

// close and save archive

$zip->close();
echo "Archive created successfully.";
?>

Thanks
Regards Supriya
Re: problem in creating Zip file [message #178812 is a reply to message #178808] Wed, 08 August 2012 14:18 Go to previous messageGo to next message
Doug Miller is currently offline  Doug Miller
Messages: 171
Registered: August 2011
Karma: 0
Senior Member
Supriya <singla(dot)supriya88(at)gmail(dot)com> wrote in news:1592f3dd-f681-4100-b6b4-
e1684b06322c(at)googlegroups(dot)com:

> 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);

Had you considered that this may not be enough time?
Re: problem in creating Zip file [message #178813 is a reply to message #178812] Wed, 08 August 2012 14:37 Go to previous messageGo to next message
Christoph Becker is currently offline  Christoph Becker
Messages: 91
Registered: June 2012
Karma: 0
Member
Doug Miller wrote:
> Supriya wrote:
>> ini_set("max_execution_time", 18000);
>
> Had you considered that this may not be enough time?

I suppose 5 h should be pretty much enough for creating a ZIP file. But
indeed changing the max_execution_time might fail (e.g. when PHP runs in
safe mode). However, if the script outputs "Archive created
successfully.", the execution time can't be the problem.

--
Christoph M. Becker
Re: problem in creating Zip file [message #178814 is a reply to message #178813] Wed, 08 August 2012 15:25 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 8/8/2012 10:37 AM, Christoph Becker wrote:
> Doug Miller wrote:
>> Supriya wrote:
>>> ini_set("max_execution_time", 18000);
>>
>> Had you considered that this may not be enough time?
>
> I suppose 5 h should be pretty much enough for creating a ZIP file. But
> indeed changing the max_execution_time might fail (e.g. when PHP runs in
> safe mode). However, if the script outputs "Archive created
> successfully.", the execution time can't be the problem.
>

Are you sure you CAN change the max execution time? Many shared hosting
environments don't allow it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: problem in creating Zip file [message #178818 is a reply to message #178813] Wed, 08 August 2012 17:46 Go to previous messageGo to next message
Doug Miller is currently offline  Doug Miller
Messages: 171
Registered: August 2011
Karma: 0
Senior Member
Christoph Becker <cmbecker69(at)gmx(dot)de> wrote in news:jvttio$ppi$1(at)speranza(dot)aioe(dot)org:

> Doug Miller wrote:
>> Supriya wrote:
>>> ini_set("max_execution_time", 18000);
>>
>> Had you considered that this may not be enough time?
>
> I suppose 5 h should be pretty much enough for creating a ZIP file. But
> indeed changing the max_execution_time might fail (e.g. when PHP runs in
> safe mode). However, if the script outputs "Archive created
> successfully.", the execution time can't be the problem.

My mistake -- I thought it specified milliseconds, not seconds. I stand corrected.
Re: problem in creating Zip file [message #178819 is a reply to message #178808] Thu, 09 August 2012 04:37 Go to previous messageGo to next message
salil.ag is currently offline  salil.ag
Messages: 1
Registered: August 2012
Karma: 0
Junior Member
try with max_execution_time with some lower value, 5 Hr is too much.


On Wednesday, 8 August 2012 12:10:25 UTC+5:30, 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);
>
>
>
>
>
> // 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");
>
> }
>
>
>
> // close and save archive
>
>
>
> $zip->close();
>
> echo "Archive created successfully.";
>
> ?>
>
>
>
> Thanks
>
> Regards Supriya
Re: problem in creating Zip file [message #178820 is a reply to message #178808] Thu, 09 August 2012 05:09 Go to previous messageGo to next message
J.O. Aho is currently offline  J.O. Aho
Messages: 194
Registered: September 2010
Karma: 0
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
Re: problem in creating Zip file [message #178848 is a reply to message #178808] Sun, 12 August 2012 17:25 Go to previous message
M. Strobel is currently offline  M. Strobel
Messages: 386
Registered: December 2011
Karma: 0
Senior Member
Am 08.08.2012 08:40, schrieb Supriya:
> 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...
>

Is the problem solved?

It could be an access restriction problem, be aware that your script runs with the
web server account.

/Str.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: How to make Apache to allow an executable to leave a file?
Next Topic: PHP Debugger which can set breakpoint and view variables on watch window
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 21 22:12:15 GMT 2024

Total time taken to generate the page: 0.03023 seconds