Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

XLSX tmp file error

by vishi83 (Pilgrim)
on Mar 02, 2012 at 11:00 UTC ( #957438=perlquestion: print w/replies, xml ) Need Help??
vishi83 has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks!!

I'm using Excel::Writer::XLSX (0.38 version) to write to xlsx files. But i seem to be getting the below error when i run my script as a CGI from the browser..

Couldn't open file /tmp/tdMZUai27q/xl/worksheets/sheet1.xml for writing.

However it is working fine if i run the script from command line. Internally the XLSX module uses File::Temp which i understand has issues with /tmp directories..
I'm using perl 5.8.7 on a HP-UX box.
I need some help to understand how to resolve this... Hope i dont to tweak the module itself to make it work..

Thanks...

Replies are listed 'Best First'.
Re: XLSX tmp file error
by jmcnamara (Monsignor) on Mar 02, 2012 at 20:15 UTC

    You can change the default temp dir that Excel::Writer::XLSX uses via the set_tempdir() method.

    --
    John.

      Hi John,

      Glad to hear from you!
      I tried with 0.46 version of XLSX module.. But after setting the tmp dir in this way,
      workbook->set_tempdir('/opt/apache/secure-htdocs/exceldir/');
      I still see this error,
      Couldn't create sub directory /opt/apache/secure-htdocs/exceldir/CQ2RN +O0V36/xl/worksheets: Permission denied at /opt/perl-5.8.3/lib/site_pe +rl/5.8.3/Excel/Writer/XLSX/Workbook.pm line 809
      I've given 777 permissions to the exceldir folder with ownership belonging to the web user..
Re: XLSX tmp file error
by bitingduck (Chaplain) on Mar 02, 2012 at 15:29 UTC

    You should look in your error logs to see if it tells you why you can't open the file, but my first guess would be a permissions problem. When you do it from the command line you're doing it in a directory that you created, so you have read/write permission. When the browser is doing it through CGI it's running as another user (probably www or something similar) and for (hopefully obvious) security reasons the www user is limited in what directories it can read/write.

    Try creating either a subdirectory in your cgi directory, or one somewhere in below the DocumentRoot for the webserver, and make sure it has the permissions set so the server can write to it

Re: XLSX tmp file error
by Anonymous Monk on Mar 02, 2012 at 11:38 UTC

    What is the reason it Couldn't open file ... for writing ( hint, print value of $! variable )?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://957438]
Approved by Corion
help
Chatterbox?
marto gasps at number of blocks in the Lego millennium falcon
[marto]: How many days till Christmas? ;)

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2017-12-18 21:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (498 votes). Check out past polls.

    Notices?