in reply to Confusing Syntax

Besides the syntax errors that others have already corrected, I'd like to make some suggestions.

You use 15 differently named input fields. Perhaps you don't know that when you create 15 that all have the same name, you can get a list from $q->param.

Photo 1: <input type=file name=photo><br> Photo 2: <input type=file name=photo><br> Photo 3: <input type=file name=photo><br> ...
#!/usr/bin/perl -w use strict; use CGI; my $cgi = CGI->new; my @pictures = $cgi->param('photo'); ...

You don't check the value of $album and then you use it. This means that anyone can create directories anywhere the web server can. Very dangerous.

The script doesn't check if open succeeded. When it can't create the file, it silently continues.

It is a very good idea to indent your code. Inside {} blocks, indent everything to visualize the block. This makes reading code much easier. Especially when you ask for help, you should do everything you can to make it easy to read.

I forgot the most important mistake. The code doesn't use strict. Always use strict!

use strict;
Your code will not work with strict without modification. A good Perl book or tutorial will tell you how to change your code. If you don't already have a good Perl book, try Beginning Perl. It's free.

Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

Replies are listed 'Best First'.
Re: Re: Confusing Syntax
by eoin (Monk) on Aug 12, 2003 at 11:57 UTC
    Thanks for the help.
    I never knew about getting a list from param. Thats pretty handy.
    I still have problems though.
    The error syntax error at upload.cgi line 73, near "while <$pic_filehandles[$cntr]>" is still present and I can't figure it out.
    Also could you please elaborate on your comment about checking the folder before using it.


    All the Best, Eoin...

    If everything seems to be going well, you obviously don't know what the hell is going on.

      I never knew about getting a list from param.

      Reading the documentation really helps.

      syntax error at upload.cgi line 73, near "while <$pic_filehandles[$cntr]>"

      You should use parentheses with while. Again, you should read the documentation.

      Also could you please elaborate on your comment about checking the folder before using it.

      Try to see what happens if the web users specifies "../hello_world" as the album.

      Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

        Sorry i was totally missing the point.
        Advice duely noted and acknowledged.
        Thanks for all the help.


        All the Best, Eoin...

        If everything seems to be going well, you obviously don't know what the hell is going on.