Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Archive::Zip errors

by fluffyvoidwarrior (Monk)
on Nov 04, 2005 at 06:55 UTC ( #505632=perlquestion: print w/replies, xml ) Need Help??
fluffyvoidwarrior has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks, I'm using archive::zip to create a zip file. My code works fine when run as a perl script but when I try to run the same code as a cgi I cannot write the output file. I get a number 4 I/O error and $! says "permission denied". I'm using exactly the same files and folders in both cases. The only difference I can see is that the script that works is run as a local non-root user and the other is www apache, All my other cgi scripts happily write to these folders but archive::zip won't.
my $zip = Archive::Zip->new(); # add all readable files and directories below . as xyz/* $zip->addTree( '/delme/wibble', 'customer_uploads' ); $zip->addFile( '/delme/wibble.tif', 'wibble.tif' ); $zip->addFile( '/delme/wibble.gif', 'wibble.gif' ); # and write them into a file $zip_return_code = $zip->writeToFileNamed('/delme/final_zipfile.zip +'); if($zip_return_code != 0){ #an error occurred doing the zip $html_string = $html_string . "Error creating zip file . . . $zip_ +return_code $! "; }
No doubt I'm doing something dumb. Would someone please enlighten me? Thanks

Replies are listed 'Best First'.
Re: Archive::Zip errors
by polettix (Vicar) on Nov 04, 2005 at 09:12 UTC
    Have you simply tried something like this (caution: works in recent Perl releases)?
    #!/usr/bin/perl -T use strict; use warnings; use CGI::Carp qw( fatalsToBrowser ); use CGI qw( :standard ); + # Try to open a simple, splendid filehandle open my $fh, ">", "/delme/final_zipfile.zip" or die "open(): $!"; + # Print a greeting message print header(), start_html("Opened successfully"), h1("Opened successfully"), end_html();
    You'd be able to work out if Archive::Zip is the real cause of your troubles. If not, try to work around using writeToFileHandle while you dig the problem in depth.

    Flavio
    perl -ple'$_=reverse' <<<ti.xittelop@oivalf

    Don't fool yourself.
      I'll try writeofilehandle Thanks

        I use absolute file path in writeToFileNamed

        $zip->writeToFileNamed("/root/abc/def/ghj.zip");
Re: Archive::Zip errors
by Skeeve (Vicar) on Nov 04, 2005 at 08:54 UTC
    The problems are here (cite):
    • I'm using exactly the same files and folders in both cases
    • the script that works is run as a local non-root user and the other is www apache
    apache will most surely not have permission to write to /delme/.

    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
Re: Archive::Zip errors
by virtualsue (Vicar) on Nov 04, 2005 at 08:01 UTC
    Are there any archive files in the target directory which are owned by the local non-root userid as a byproduct of your development testing? If so, get rid of them because www:apache probably doesn't have permission to clobber them.
      No, no zip files at all in target folder.
        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?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://505632]
Approved by gam3
Front-paged by diotalevi
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2018-01-23 22:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How did you see in the new year?










    Results (254 votes). Check out past polls.

    Notices?