http://www.perlmonks.org?node_id=505657


in reply to Re^2: Archive::Zip errors
in thread Archive::Zip errors

Then is this statement from your original post correct?

All my other cgi scripts happily write to these folders but archive::zip won't

Are you *sure* that www:apache can create files in the /delme/ directory?

Replies are listed 'Best First'.
Re^4: Archive::Zip errors
by fluffyvoidwarrior (Monk) on Nov 04, 2005 at 09:57 UTC
    Just added :
    open(WOBBLE, ">/delme/flunk.txt"); print WOBBLE "Bugger!"; close(WOBBLE);
    to my cgi script and you're right apache wont write to the /delme directory. However, I then tested it on my actual real life directory with this code
    open(WOBBLE, ">/caralan_com/system/proofing/cam_proofs/steve/live/fl +unk.txt"); print WOBBLE "Bugger!"; close(WOBBLE);
    and the file is created as expected. It sounds like I have my permissions set wrong and that perhaps archive::zip is less forgiving than apache. I'll try opening my permissions and owner to something totally public all along that path and see what happens.
      I have not seen anything yet which indicates that this problem has anything to do with Archive::Zip. What is important here is the fact that your CGI scripts run as www, so the www user must have write permission in the locations specified in your scripts.

      You will make your life easier as well as more secure if you set up a development environment which has the same underlying directory structure & permissions as your target production environment, rather than writing test files in random places on your hard drive. :)

        Yes, That seems sensible and it is how I normally work. I use the /delme folder for shared junk with very loose security which is why I tested it there when I thought I had a permissions problem. Mainly I wanted to know that I wasn't doing anything dumb with archive::zip since I have about 20mins experience with it but was pretty certain of my code since it was lifted from the man page and the names changed. Thanks for your help. It doesm't seem like a perl or archive::zip problem so unless you have any other thoughts I'll "poke it with a stick" and trust to luck ...

      It sounds like I have my permissions set wrong and that perhaps archive::zip is less forgiving than apache. I'll try opening my permissions and owner to something totally public all along that path and see what happens.

      Well, you're getting *very* close. Archive::Zip has nothing to do with permissions directly. I'm almost postive that what you're missing is that apache runs on one user account, that quite likely has slightly different permissions than your login user account.

      When you execute a CGI manually, you're running as *you*. Meanwhile, when one is called via the Apache daemon, it's running as (apache|httpd|etc.).

        The apache daemon will write to these directories in response to events from remote users interaction via cgi. When the same remote connection to the same cgi script invokes archive::zip it wiill not write a file. This code will write to disk:
        open(WOBBLE, ">/caralan_com/system/proofing/cam_proofs/steve/live/fl +unk2.txt"); my $zip = Archive::Zip->new(); $zip->addTree( '/delme/wibble', 'customer_uploads' ); $zip_return_code = $zip->writeToFileHandle('WOBBLE'); close(WOBBLE);
        But this will not:
        my $zip = Archive::Zip->new(); $zip->addTree( '/delme/wibble', 'customer_uploads' ); $zip_return_code = $zip->writeToFileNamed('/delme/$proofstem.zip');