I've currently been working on a online photo album "sort of thing". I'm using cgi scripts to do everything from generate pages to resizing images. its a large enough project for some one as inexperienced as me but I'm glad to say that its coming along nicely.
I've only had one main problem so far and thats been the file upload script. Seeing as I've never done one before or even seen one, I was bound to have trouble with it.
I've been a while at it and I think I have it but...
Perl keeps throwing up these silly, confusing syntax errors and I'm stumped. I'm probably just not seeing whats wrong.
Also if you could tell me whether my way of uploading is, first of all, right and/or is there another "better" way to do this.
These are the errors Perl is giving me:
syntax error at upload.cgi line 18, near "%pics("
syntax error at upload.cgi line 36, near "@pic_filehandles("
syntax error at upload.cgi line 73, near "while <$pic_filehandles[$cnt
+r]>"
syntax error at upload.cgi line 80, near "}"
And heres the code
I've inserted a line of hashes just before the error lines just to save you counting.
#!/usr/bin/perl -w
use CGI;
$q = new CGI;
my $album = $q->param("T1");
unless ( -d "./albums/$album" ) {
mkdir( "./albums/$album", 0775 ) || die "Can't create $webpage_dir: (
+$!)\n";
}
my $upload_dir = "albums/$album";
############################################
%pics(
pic0 => $q->param("photo") ,
pic1 => $q->param("photo1") ,
pic2 => $q->param("photo2") ,
pic3 => $q->param("photo3") ,
pic4 => $q->param("photo4") ,
pic5 => $q->param("photo5") ,
pic6 => $q->param("photo6") ,
pic7 => $q->param("photo7") ,
pic8 => $q->param("photo8") ,
pic9 => $q->param("photo9") ,
pic10 => $q->param("photo10") ,
pic11 => $q->param("photo11") ,
pic12 => $q->param("photo12") ,
pic13 => $q->param("photo13") ,
pic14 => $q->param("photo14")
);
#########################################
@pic_filehandles(
$q->upload("photo") ,
$q->upload("photo1") ,
$q->upload("photo2") ,
$q->upload("photo3") ,
$q->upload("photo4") ,
$q->upload("photo5") ,
$q->upload("photo6") ,
$q->upload("photo7") ,
$q->upload("photo8") ,
$q->upload("photo9") ,
$q->upload("photo10") ,
$q->upload("photo11") ,
$q->upload("photo12") ,
$q->upload("photo13") ,
$q->upload("photo14")
);
strip_filename();
sub strip_filename{
my @allkeys = sort(keys(%pics));
foreach $key (@allkeys){
$pics{$key} =~ s/.*[\/\\](.*)/$1/;
}
}
my $cntr = "0";
@files = sort(keys(%pics));
foreach $key (@files){
open IMAGE, ">$upload_dir/$pics{$key}";
binmode IMAGE;
########################################
while <$pic_filehandles[$cntr]>
{
print IMAGE;
}
close IMAGE;
$cntr += 1;
#############################################
}
print $q->header ( );
print <<END_HTML;
<HTML>
#RANDOM HTML
</HTML>
END_HTML
I'm stumped so any and all help will be greatly appriciated.
All the Best, Eoin...
If everything seems to be going well, you obviously don't know what the hell is going on.