katgirl has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Can't find where 500 error is coming from
by fglock (Vicar) on Sep 06, 2002 at 16:13 UTC | |
|
•Re: Can't find where 500 error is coming from
by merlyn (Sage) on Sep 06, 2002 at 16:30 UTC | |
|
Re: Can't find where 500 error is coming from
by theorbtwo (Prior) on Sep 06, 2002 at 16:36 UTC | |
|
Re: Can't find where 500 error is coming from
by katgirl (Hermit) on Sep 09, 2002 at 08:05 UTC |