ketaki has asked for the wisdom of the Perl Monks concerning the following question:

Software error: CGI open of tmpfile: Read-only file system i am getting this error on the page where i am uploading the excel file to the server. the code is below:

#!/usr/bin/perl use CGI; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use strict; use warnings; use diagnostics; use File::Basename; use CGI::SSI (autotie => 'STDOUT'); print CGI::header(); my $body; my $username="xxxxx"; my $password="xxxxx"; my $step =param('step'); my $user =param('user'); my $pass =param('pass'); my $excelfile =param('excelfile'); if ( (! defined $step) || (($step == 1) && ( ($user ne $username) || ( +$pass ne $password) ) ) ) { if (defined $step) { $body.= "<br><br>Incorrect Username or Password<br><br>" } $body.=<<htmlx; <form action="http://xxxxxxxxxxxxxxxx.org/cgi-bin/update.cgi" meth +od=post> ADMINISTRATOR LOGIN <br><br> Username : <input type=text name="user"> Password : <input type=password name="pass"> <input type=hidden name="step" value=1> <input type=submit value="Login"> </form> htmlx } else { if (($user eq $username) && ($pass eq $password)) { if ($step == 1) { $body.=<<htmlx; <form action="http://xxxxxxxxxxxxx.org/cgi-bin/update.cgi" met +hod=post> Upload excel file <input type=file name="excelfile" chars=40> <input type=hidden name="step" value=2> <input type=hidden name="user" value=$user> <input type=hidden name="pass" value=$pass> <input type=submit value="Submit"> </form> htmlx } # if ($step == 2) # { # my $query = new CGI; # my $upload_dir = "/home/www/xxxxxxxxxxxxxxxxxxx.org/excel"; # my $upload_filehandle = $query->upload("$excelfile"); # # open(EXCELFILE, ">$upload_dir/infosheet.xls"); # chmod("$upload_dir/infosheet.xls",0777); # while ( <$upload_filehandle> ) # { # print EXCELFILE; # } # close(EXCELFILE); # # } } } local $/ = undef; open(file, "/home/www/xxxxxxxxxxxxxxxxxxxxx.org/forcgi.shtml"); my $filedata= <file>; $filedata =~ s/\$body/$body/; close(file); print $filedata;

Replies are listed 'Best First'.
Re: software error regarding as described below
by moritz (Cardinal) on Jul 16, 2008 at 13:45 UTC
    Did you actually read the error message you were getting?
    Software error: CGI open of tmpfile: Read-only file system

    If you upload a file, CGI tries to open a temporary file. That fails because the file system that CGI uses for temporary files is mounted as read-only.

    So, mount your file system as rw, and all is fine.

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: software error regarding as described below
by zentara (Cardinal) on Jul 16, 2008 at 13:48 UTC
    Unless you are running suexec, your $upload_dir has to be mode 777 (world writable) because the server runs at the lowest permission possible. You seem to be making your uploaded file 0777, but the directory it goes into must be 0777. It can get tricky. :-)

    I'm not really a human, but I play one on earth CandyGram for Mongo

      No, it doesn't have to be world writable; it just has to be writable by the uid which the CGI (and/or web server) is running as. Often in shared hosting setups you can't achieve this other than by making the directory wide open, but if you've got more control it's better to avoid opening things up more than you have to.</pedant>

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.

        Thats why I prefaced it with "with suexec". That is what I'm familiar with under apache, that lets the apache run as the user in his own home dir. But it's been a few years since I've done an httpd.conf file setup.... it's amazing all the options and juggling they do now. It's probably possible nowadays to make an .htaccess edit, to get write permissions. :-)

        I'm not really a human, but I play one on earth CandyGram for Mongo