I'm probably overlooking something blindingly obvious, but it's nearly hometime and I'm not in the mood!

OK, I'm trying to write a storybook that has pictures attached, my users sign up and get a password, then they can upload their story and an optional picture to the storybook.

Below is the upload script - when I run it, even with no picture uploaded, I get a 500 server error. I've tried running it from the command line, but I don't get any error there. I know it probably looks hopelessly messy, but I keep changing bits to try to find out where I've gone wrong and nothing seems to help. *starts to dribble*

Help me, oh wisdomful monks, before I go insane...

#!/usr/bin/perl -w use CGI::Carp qw(fatalsToBrowser); #place to go when successful $redirect = "http://www.mysite.com/soapopera/start.cgi"; #absolute location of the directory for your images $Data = "/usr/local/www/virtual/username/soapopera/images"; #file containing usernames and passwords $datafile = "passes.txt"; #File extensions to allow your visitors to upload. @good_extensions = ('gif', 'jpg', 'jpeg', 'png'); #maximum file size in Kb $max_size_main = 25; #Gives date as "Weekday, Daynumber Month Year" use POSIX qw(strftime); $time= strftime("%A, %d %B %Y", localtime); use CGI; my $req = new CGI; my $name = $req->param("name"); my $password = $req->param("password"); my $title = $req->param("title"); my $story = $req->param("story"); my $storyid = $req->param("storyid"); my $image = $req->param("image"); my $next1 = $req->param("next1"); my $next2 = $req->param("next2"); my $chapter = $req->param("chapter"); my $imagename = $image; $story =~ s/\n/<br>/gi; open(PASSFILE, $datafile) or die $!; @data = <PASSFILE>; close(PASSFILE); foreach $data(@data){ @eachinfo = split(/\|/, $data); if ($eachinfo[0] eq $name && $eachinfo[2] eq $password){ $success = 1; } } if (!$success){ print "<h1>Sorry</h1>That Name/Password combination is not correct. Pr +ess your back button and try again."; } if($success){ if($image) { $imagename =~ s/^.*(\\|\/)//; $imagename =~ s/ +/\_/g; $num=""; while(-e "$Data/$num$imagename"){ $num++; } $imagename = $num.$imagename; my $proceed_type = 0; foreach(@good_extensions) { my $ext = $_; $ext =~ s/\.//g; if($imagename =~ /\.$ext$/) { $proceed_type = 1; last; } } unless($proceed_type) { push(@was_not_good_type, $imagename); } if($proceed_type) { if(open(OUTFILE, ">$Data/$imagename")) { while (my $bytesread = read($image, my $buffer, 1024)) { print OUTFILE + $buffer; } close (OUTFILE); push(@file_did_save, $imagename); } else { push(@did_not_save, $imagename); } } if($max_size_main) { if((-s "$Data/$imagename") > ($max_size_main * 1024)) { push(@was_too_big, $imagename); unlink("$Data/$imagename"); } } #close if file exists... if(@file_did_save){ open (TXTFILE, ">>data/$storyid.txt") or die $!; print TXTFILE "$chapter|$name|$title|$story|$next1|$next2|$imagename|$ +time\n"; close(TXTFILE); print $req->redirect($redirect); } else{ if(@was_not_good_type){ @reason = @was_not_good_type;} if(@was_too_big){@reason = @was_too_big;} if(@did_not_save){@reason = @did_not_save;} print "Content-type: text/html\n\n"; print "An error occured: @reason"; exit; } }else{ #no pic uploaded open (TXTFILE, ">>data/$storyid.txt") or die $!; print TXTFILE "$chapter|$name|$title|$story|$next1|$next2||$time\n"; close(TXTFILE); print $req->redirect($redirect); } }#successful password

In reply to Can't find where 500 error is coming from by katgirl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.