• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 507
  • Last Modified:

Flash write to text file with CGI

Hi,

I have a cgi script:

#!/sbcimp/run/pd/perl/prod/bin/perl

use CGI;

my $query = new CGI;

my $theusername = $query->param("user_name");
my $thegpn = $query->param("user_gpn");
my $thecompleted = $query->param("completed");
my $logtime = localtime(time);

open (LOG, ">>log.txt");
print LOG "$logtime, $theusername, $thegpn, $thecompleted";
close (LOG);

exit;


I'm simply trying to write some data from a Flash movie (with loadvariablenum) to a text file but it just isn't working with this script. Any help would be appreciated.

JR
0
jesserobbins
Asked:
jesserobbins
  • 3
  • 2
1 Solution
 
kanduraCommented:
You really should check if the open() succeeded. Try this script:

    #!/sbcimp/run/pd/perl/prod/bin/perl
   
    use CGI;
   
    my $query = new CGI;
   
    print $query->header;   # standard http header
   
    my $theusername = $query->param("user_name");
    my $thegpn = $query->param("user_gpn");
    my $thecompleted = $query->param("completed");
    my $logtime = localtime(time);
   
    unless( open(LOG, ">>log.txt") ) {
        print "Error opening log.txt: $!";
        exit;
    }
   
    print LOG "$logtime, $theusername, $thegpn, $thecompleted";
    close (LOG);


Now call up the script in your browser by entering its url:

    http://yourhosthere/path/to/script.pl?user_name=test&user_gpn=test&completed=test

Modify the first part to your specifics.

Let us know what that printed. If the page is blank, you should see something in log.txt, and otherwise you will see the error.
0
 
jesserobbinsAuthor Commented:
Hi,

Thanks for the reply. I get the following:

Error opening log.txt: Permission denied

JR
0
 
kanduraCommented:
Well, there you have it!

Your script may have worked, but you're not allowed to write to the log file from within a cgi program.
To fix that, you'd need to give the web server account write permissions on log.txt.
0
 
jesserobbinsAuthor Commented:
Is that something I can do from telnet access or do I have contact my server admin?
0
 
kanduraCommented:
you can do that with telnet. It does depend on how your server is configured, though, so it's hard to give specific instructions.
If it's a unixy type of OS, then you'd use the chmod or the chown command. What I'd suggest doing is making the webserver user the owner of the file, and then set read/write permission for the owner, and read permission for the group. On my host, that would mean:

    chown apache log.txt
    chmod o+rw,g+r log.txt

0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now