Avatar billede kenneth_jakel Nybegynder
12. marts 2001 - 19:46 Der er 19 kommentarer og
1 løsning

modificering af cgi/perl script

hej, jeg har downloaded følgende cgi/perl script til at uploade filer til serveren med jeg har lagt det som en txt-fil her:

http://www.flare.dk/cgi-bin/upload_cgi.txt

det virker helt fint, men jeg søger én med forstand på perl, der kan modificerer det for mig:

Det skal bruges til at oploade billedfiler der skal vises en en nyheds-sektion. Jeg har tænkt mig at \"opbevarer\" nyheder og billedernes filnavne i en MySQL database, og så trække dem ud vha. PHP.

Derfor skal jeg gerne have cgi/perl scriptet til at skrive de oploadede filers navne ind i min database, og det er her I eksperter kommer ind i billedet.

Jeg laver naturligvis en formular på en foregående html, der fører filerne (variablerne) videre til scriptet. formularen ser ud som følger:

<FORM METHOD=\"POST\" ACTION=\"cgi-bin/upload.cgi\" ENCTYPE=\"multipart/form-data\">
File 1: <INPUT TYPE=\"FILE\" NAME=\"FILE1\">
File 2: <INPUT TYPE=\"FILE\" NAME=\"FILE2\">
File 3: <INPUT TYPE=\"FILE\" NAME=\"FILE3\">

<INPUT TYPE=\"SUBMIT\" VALUE=\"Upload!\">
</FORM>


(grunden til at jeg vælger Perl (som jeg absolut ikke ved noget om) er at serveren som siderne skal ligge på, ikke understøtter upload af filer med f.eks. PHP.

håber der er nogen der kan hjælpe mig
/kenneth 

NB. Jeg er naturligvis åben for forslag til løsninger der kan give samme resultat...jeg skal bare have hjælp til udførsel af dem.
Avatar billede Thomas Nybegynder
12. marts 2001 - 19:57 #1
Hvorfor ikke få Perl scriptet til at lave en ny form (evt. hidden med automatisk submit) hvor du bare kalder et php script der smider det ind i din mysql database? Det skulle være en forholdsvis hurtigt overset løsning....
Avatar billede kenneth_jakel Nybegynder
12. marts 2001 - 21:10 #2
jo, det lyder som en rigtig god ide. jeg er lidt i tvivl om hvordan det skal gøres.....Det kunne jeg dog nok finde ud af ved at kigge andetsted i scriptet.

Alligevel vil jeg nu gerne have én til at lave det for mig, så hvis du er frisk på det?

/kenneth

Avatar billede Thomas Nybegynder
12. marts 2001 - 21:51 #3
Jeg kan studere det imorgen, håber du kan vente så længe!

Hvordan vil du så have det?
Som en form med 3 input felter med navnene allerede skrevet ind, eller
som en form med samme antal felter, men som submitter sig selv...

...begge kalder selvf. et php script så du selv kan smide det i din database..
Avatar billede kenneth_jakel Nybegynder
12. marts 2001 - 22:24 #4
Det lyder fedt. Jeg vil gerne have løsningen, der submitter sig selv.

/kenneth
Avatar billede Thomas Nybegynder
13. marts 2001 - 18:25 #5
Jeg har foretaget nogle ændringer i scriptet - jeg poster det her, men jeg tror desværre at eksperten får delt linierne forkert, så hvis du vil have det pr. e-mail er det iorden!
Avatar billede Thomas Nybegynder
13. marts 2001 - 18:26 #6
#!/usr/bin/perl

#######################################################################################
#
#    PSUpload Helper (PSUpload) V2.0
#    ©2001, Jim Melanson
#    jim@perlservices.com, info@charityware.ws
#
#    Requirements:        UNIX Server, Perl5+
#    Created:        September 22nd, 2000
#    Author:         Jim Melanson, Owner and Lead Programmer
#    Contact:        www.perlservices.com, www.charityware.ws
#                Phone:        1-705-437-3283
#                Fax:        1-208-694-1613
#                E-Mail:        info@perlservices.com
#
#    This utility is distributed under the same terms as Perl itself. It may be
#    modified and utilized as you will so long as the original copyright notice
#    remains in the header and that any modifications you make are state in the
#    header along with the date of the modification and the name and email addy
#    of the person who made the modification.
#
#    Additionally, this program has been designated as Charity Ware. That means
#    that if you use the program or modify the program to use it in/with another
#    program then you are required to make a charitable donation to a charity
#    of YOUR choice in the amount of YOUR choice. We\'d appreciate your dropping
#    by Charity Ware (www.charityware.ws) to register your donation so others can
#    see who is benefiting from our work. If your too busy, drop us a line telling
#    us who benefited and how much you gave them and we\'ll post the registration
#    for you.
#
#    This program requires installation on a UNIX server running Perl4 or higher.
#
#    This program require the use of the CGI.pm module. If it is not installed
#    on your server, you can have your sysadmin obtain the latest version of CGI.pm
#    form the CPAN site at www.cpan.org
#
#    Please see the accompanying HTML demonstration file for instructions on
#    creating the upload form you will put on your HTML page.
#
#    History:
#    This program was originally written in a basic form by Mark Knickelbain. After
#    Perl Services was taken over by Jim Melanson, this utility was re-written. This
#    re-write has been based on the feedback of hundreds of users. The features
#    incorporated in the re-write were the most common requests of PSUpload Helper
#    users. Version 2.0 of this program was released on February 22nd, 2001.
#
#    It was the authors choice that PSUpload Helper 2.0 should be distributed from
#    the Charity Ware site at www.charityware.ws so that others less fortunate may
#    benefit from his efforts.
#
#######################################################################################
#
#    FINAL WORD:    Do you have comments or criticisms (constructive ones) please
#            send them to jim@perlservices.com or info@charityware.ws. This
#            library and the V2 of PSUpload Helper are the results of input
#            from end users and incorporate the most common requests.
#
#######################################################################################
#
#    CONFIGURE VARIABLES

$Data = \"/www/flare.dk/web/images\";
    #    On your server, create a directory where this program will write the files
    #    to. Make sure you CHMOD this directory to 777. If you do NOT specify a $Data
    #    directory, the program will attempt to write to the web root directory.
    #    NOTE: YOU SHOULD ALWAYS SPECIFY A DIRECTORY TO STORE THE UPLOAD

@good_extensions = (\'gif\', \'jpg\', \'jpeg\');
    #    If you want to limit the types of extension that can be uploaded, specify them
    #    here by adding them to the array. For example, if you wanted to permit only
    #    the upload of gif\'s, jpg\'s and png\'s, then you would set the above array to
    #    look like this:
    #    @good_extensions = (\'gif\', \'jpg\', \'jpeg\', \'png\');
    #

@bad_extensions = ();
    #    If you want to permit the upload of all file types with only certain exceptions,
    #     then specify those extensins in the bad_extensions array. This means that if set
    #  this array to contain .exe, .pl, .cgi files, then the program will only store a
    #    file if the extension of that file is NOT found in this array.
    #    To set the array to exclude these sample extensions, you would set it like this:
    #    @bad_extensions = (\'exe\', \'cgi\', \'pl\');
    #

    #    NOTE: If you specify both @good_extensions and @bad_extensions, then
    #    the settings in @bad_extensions will be ignored and the program will
    #    use @good_extensions as it\'s refrence.

$redirect = \"\";
    #    When the upload of files is complete, the program must print someting out on the
    #    browser screen. Set the $redirect variable to the full URL (don\'t forget the http://)
    #    that you want the person taken to once the program is finished. If you don\'t specify
    #    a URL here, the program will print out a simple upload summary page.

$max_size = 50;
    #    Set the maximum size of each file that is permitted. For example, if you only want
    #    files to be uploaded that are under 50Kb in size, set the value to:
    #    $max_size = 50;
    #    If you set the value to zero, remove it or comment it out, then the size of the
    #    uploaded file will NOT be checked.

$max_num_files = 3;
    #    You must specify the maximum number of files that can be uploaded at one time. You
    #    can set this to any number you want but be realistic. The limit before the server
    #    times out will depend on the maximum size of the upload. I have tested this program
    #    with ASCII files up to 8MB in size successfully but that was on a particularly
    #    robust server. I recommend that you set this no higher than 5 if you are going to
    #    be using this for larger binary files such as images or executables or word docs, etc.
    #    If you remove, comment out or set this value to zero, the program will default the
    #    value to 1 file.

  # --> Tilføjet af Thomas Palm 13/3-01
$tilphp = \"http://www.ditdomæne.dk/ditphpscript.php\";
  # Angiver hvilket script denne side bliver submitted til!!
  # PHP scriptet skal checke file1-max_num_files for værdier!

$nykode  = \"<form action=\\\"$tilphp\\\" name=\\\"tilphp\\\">\";
  # Koden der starter formularen... Der bliver tilføjet mere til denne senere...

#
#######################################################################################
#
#            DO NOT EDIT ANYTHING BELOW THIS LINE
#            UNLESS YOU KNOW WHAT YOU ARE DOING
#

if(($ENV{\'QUERY_STRING\'} =~ /^debug/) && !$no_debug) {
    print \"Pragma: no-cache\\nContent-type: text/html\\n\\n\";
    print \"<TITLE>PSUpload Demonstration Upload Program - Debug Mode</TITLE></HEAD><BODY BGCOLOR=\\\"#ffffff\\\" TEXT=\\\"#330066\\\" LINK=\\\"#336666\\\" ALINK=\\\"#336666\\\" VLINK=\\\"#336666\\\" BGCOLOR=\\\"#FFFFFF\\\"><FONT SIZE=\\\"2\\\" FACE=\\\"verdana, arial, helvetica\\\">\\n\";
    print \"<CENTER><B><H2>Charity Ware\'s PSUpload Program</H2></B><BR><BR><TABLE BORDER=0><TR><TD COLSPAN=2><FONT SIZE=\\\"2\\\" FACE=\\\"verdana, arial, helvetica\\\">\\n\";
    print \"<DL><DT><B>Your web root directory appears to be located at:</B><DD>$ENV{\'DOCUMENT_ROOT\'}<BR><BR><DT><B>You specified directory for storing the uploads is:</B><DD>$Data<BR><BR><DT><B>Your specified directory...</B><DD>\\n\";
    if(-d $Data) {
    print \"...appears to be a valid directory.<BR><BR>Make sure this \\$Data directory is CHMOD 777.\\n\";
    } else {
    print \"...does not appear to be a valid directory.<BR><BR>\\n\";
    unless($Data =~ /^$ENV{\'DOCUMENT_ROOT\'}/) {
        print \"The value you specified in the \\$Data variable is incorrect. Please<BR>correct your \\$Data variable and run debug again.<BR><BR>\\n\";
    }
    }
    if($Data =~ /\\/$/) {
    print \"<FONT COLOR=\\\"#FF0000\\\">NOTE: Your variable \\$Data ends with a trailing slash. Please<BR>remove this trailing slash, upload the program again<BR>and run debug once more to see if you have a valid directory.</FONT><BR><BR>\\n\";
    }
    print \"</DL><BR><BR></FONT></TD></TR><TR><TD WIDTH=\\\"50%\\\" VALIGN=\\\"TOP\\\"><FONT SIZE=\\\"2\\\" FACE=\\\"verdana, arial, helvetica\\\"><B>OS:</B><BR>$^O<BR><BR><B>Perl:</B><BR>$]</FONT></TD><TD VALIGN=\\\"TOP\\\"><FONT SIZE=\\\"2\\\" FACE=\\\"verdana, arial, helvetica\\\"><B>Installed:</B><BR>\"; my @inst = split(/\\//, $ENV{\'SERVER_SOFTWARE\'}); print join(\"<BR>\", @inst); print\"</FONT></TD></TR></TABLE><BR><BR><BR><BR><A HREF=\\\"http://www.charityware.ws/\\\">&copy; 2001, Jim Melanson</A></CENTER><BR><BR></FONT></BODY></HTML>\\n\";
} else {
    use CGI;
    $max_num_files  ||= 1;
    $Data         ||= $ENV{\'DOCUMENT_ROOT\'};
    undef @bad_extensions if @good_extensions;
    for(my $a = 1; $a <= $max_num_files; $a++) {
      $tael = $a; # --> Tilføjet af Thomas Palm 13/3-01 - Sikrer at vi har tæller værdien..
    my $req = new CGI;
    if($req->param(\"FILE$a\")) {
        my $file = $req->param(\"FILE$a\");
        my $filename = $file;
        $filename =~ s/^.*(\\\\|\\/)//;
        my $proceed_type = 0;
        if(@good_extensions) {
        foreach(@good_extensions) {
            my $ext = $_;
            $ext =~ s/\\.//g;
            if($filename =~ /\\.$ext$/) {
            $proceed_type = 1;
            last;
            }
        }
        unless($proceed_type) {
            push(@was_not_good_type, $filename);
        }
        }
        elsif(@bad_extensions) {
        $proceed_type = 1;
        foreach(@bad_extensions) {
            my $ext = $_;
            $ext =~ s/\\.//g;
            if($filename =~ /\\.$ext$/) {
            $proceed_type = 0;
            last;
            }
        }
        unless($proceed_type) {
            push(@was_a_bad_type, $filename);
        }
        } else {
        $proceed_type = 1;
        }
        if($proceed_type) {
        if(open(OUTFILE, \">$Data/$filename\")) {
            while (my $bytesread = read($file, my $buffer, 1024)) {
            print OUTFILE $buffer;
            }
            close (OUTFILE);
            push(@file_did_save, $filename);
            # --> Tilføjet af Thomas Palm 13/3-01.
            $nykode .= \"<input type=\\\"hidden\\\" name=\\\"file\".$tael.\"\\\">\\n\";
        } else {
            push(@did_not_save, $filename);
        }
        }
        if($max_size) {
        if((-s \"$Data/$filename\") > ($max_size * 1024)) {
            push(@was_too_big, $filename);
            unlink(\"$Data/$filename\");
        }
        }
    }
    }
    $nykode .= \"</form>\"; # --> Tilføjet af Thomas Palm 13/3-01 - Afslutter vores \"fake\"form..
    $spring  = \'<script language=\"javascript\">\';
    $spring .= \'document.forms[\'tilphp\'].submit();\';
    $spring .= \'</script>\'; # Dette script submitter formen automatisk....
    print \"Pragma: no-cache\\n\";
    if($redirect && ($redirect =~ /^http\\:\\/\\//)) {
    print \"Location: $redirect\\n\\n\";
    } else {
    print \"Content-type: text/html\\n\\n\";
    print \"<HEAD><TITLE>PSUpload Results</TITLE></HEAD><BODY><FONT FACE=\\\"verdana,helvetica,arial\\\" SIZE=2><BR><BR><CENTER><B><H2>Upload Results</H2></B><HR WIDTH=\\\"65%\\\"><BR><BR>\\n\";
    if(@file_did_save) {print \"<B>The following file(s) were saved:<BR><BR>\\n\"; print join(\"<BR>\", @file_did_save); print \"<BR><BR>\\n\"; print \"$nykode\\n\"; print \"$spring\\n\";}
    if(@was_not_good_type) {print \"<B>The following file(s) were not stored as their file extension<BR>did not match any of the valid extensions specified in the program:<BR><BR>\\n\"; print join(\"<BR>\", @was_not_good_type); print \"<BR><BR>\\n\"}
    if(@was_a_bad_type) {print \"<B>The following files were not stored as their file extension<BR>are on the list of extensions not permitted for upload:<BR><BR>\\n\"; print join(\"<BR>\", @was_a_bad_type); print \"<BR><BR>\\n\"}
    if(@was_too_big) {print \"<B>The following files were not stored as their file size<BR>exceeded the maximum file size of $max_size Kb.:<BR><BR>\\n\"; print join(\"<BR>\", @was_too_big); print \"<BR><BR>\\n\"}
    if(@did_not_save) {print \"<B>The following files were not stored because the<BR>program could not open their destination file:<BR><BR>\\n\"; print join(\"<BR>\", @did_not_save);print \"<BR><BR>\\n\";
            if(!@file_did_save) {print \"<FONT COLOR=\\\"RED\\\"><B>NOTE: Check to ensure that the \\$Data variable reflects the correct<BR>absolute path to the directory these files should be store in.</B></FONT><BR><BR>\"}
    }
    print \"<BR><BR><HR WIDTH=\\\"65%\\\"><BR><A HREF=\\\"http://www.charityware.ws/psupload/psupload.shtml/\\\"><FONT COLOR=\\\"#C0C0C0\\\">&copy; 2001, Jim Melanson</FONT></A><BR></BODY></HTML>\\n\";
    }
}
Avatar billede Thomas Nybegynder
13. marts 2001 - 18:27 #7
Btw; det er ikke testet, så sig lige til hvis det brokker sig (o:
Avatar billede Thomas Nybegynder
13. marts 2001 - 18:30 #8
Hov - har glemt en ting - i linien hvor der står

$nykode  = \"<form action=\\\"$tilphp\\\" name=\\\"tilphp\\\">\";

i \"initialiseringen\" skal der istedet stå...

$nykode  = \"<form action=\\\"$tilphp\\\" name=\\\"tilphp\\\" method=\\\"post\\\">\";

..havde jeg desværre glemt i farten...
Avatar billede Thomas Nybegynder
13. marts 2001 - 18:32 #9
Øjza.. har også lavet en anden fejl.. poster lige scriptet igen.. DOH!! Dumme fejl!!

#!/usr/bin/perl

#######################################################################################
#
#    PSUpload Helper (PSUpload) V2.0
#    ©2001, Jim Melanson
#    jim@perlservices.com, info@charityware.ws
#
#    Requirements:        UNIX Server, Perl5+
#    Created:        September 22nd, 2000
#    Author:         Jim Melanson, Owner and Lead Programmer
#    Contact:        www.perlservices.com, www.charityware.ws
#                Phone:        1-705-437-3283
#                Fax:        1-208-694-1613
#                E-Mail:        info@perlservices.com
#
#    This utility is distributed under the same terms as Perl itself. It may be
#    modified and utilized as you will so long as the original copyright notice
#    remains in the header and that any modifications you make are state in the
#    header along with the date of the modification and the name and email addy
#    of the person who made the modification.
#
#    Additionally, this program has been designated as Charity Ware. That means
#    that if you use the program or modify the program to use it in/with another
#    program then you are required to make a charitable donation to a charity
#    of YOUR choice in the amount of YOUR choice. We\'d appreciate your dropping
#    by Charity Ware (www.charityware.ws) to register your donation so others can
#    see who is benefiting from our work. If your too busy, drop us a line telling
#    us who benefited and how much you gave them and we\'ll post the registration
#    for you.
#
#    This program requires installation on a UNIX server running Perl4 or higher.
#
#    This program require the use of the CGI.pm module. If it is not installed
#    on your server, you can have your sysadmin obtain the latest version of CGI.pm
#    form the CPAN site at www.cpan.org
#
#    Please see the accompanying HTML demonstration file for instructions on
#    creating the upload form you will put on your HTML page.
#
#    History:
#    This program was originally written in a basic form by Mark Knickelbain. After
#    Perl Services was taken over by Jim Melanson, this utility was re-written. This
#    re-write has been based on the feedback of hundreds of users. The features
#    incorporated in the re-write were the most common requests of PSUpload Helper
#    users. Version 2.0 of this program was released on February 22nd, 2001.
#
#    It was the authors choice that PSUpload Helper 2.0 should be distributed from
#    the Charity Ware site at www.charityware.ws so that others less fortunate may
#    benefit from his efforts.
#
#######################################################################################
#
#    FINAL WORD:    Do you have comments or criticisms (constructive ones) please
#            send them to jim@perlservices.com or info@charityware.ws. This
#            library and the V2 of PSUpload Helper are the results of input
#            from end users and incorporate the most common requests.
#
#######################################################################################
#
#    CONFIGURE VARIABLES

$Data = \"/www/flare.dk/web/images\";
    #    On your server, create a directory where this program will write the files
    #    to. Make sure you CHMOD this directory to 777. If you do NOT specify a $Data
    #    directory, the program will attempt to write to the web root directory.
    #    NOTE: YOU SHOULD ALWAYS SPECIFY A DIRECTORY TO STORE THE UPLOAD

@good_extensions = (\'gif\', \'jpg\', \'jpeg\');
    #    If you want to limit the types of extension that can be uploaded, specify them
    #    here by adding them to the array. For example, if you wanted to permit only
    #    the upload of gif\'s, jpg\'s and png\'s, then you would set the above array to
    #    look like this:
    #    @good_extensions = (\'gif\', \'jpg\', \'jpeg\', \'png\');
    #

@bad_extensions = ();
    #    If you want to permit the upload of all file types with only certain exceptions,
    #     then specify those extensins in the bad_extensions array. This means that if set
    #  this array to contain .exe, .pl, .cgi files, then the program will only store a
    #    file if the extension of that file is NOT found in this array.
    #    To set the array to exclude these sample extensions, you would set it like this:
    #    @bad_extensions = (\'exe\', \'cgi\', \'pl\');
    #

    #    NOTE: If you specify both @good_extensions and @bad_extensions, then
    #    the settings in @bad_extensions will be ignored and the program will
    #    use @good_extensions as it\'s refrence.

$redirect = \"\";
    #    When the upload of files is complete, the program must print someting out on the
    #    browser screen. Set the $redirect variable to the full URL (don\'t forget the http://)
    #    that you want the person taken to once the program is finished. If you don\'t specify
    #    a URL here, the program will print out a simple upload summary page.

$max_size = 50;
    #    Set the maximum size of each file that is permitted. For example, if you only want
    #    files to be uploaded that are under 50Kb in size, set the value to:
    #    $max_size = 50;
    #    If you set the value to zero, remove it or comment it out, then the size of the
    #    uploaded file will NOT be checked.

$max_num_files = 3;
    #    You must specify the maximum number of files that can be uploaded at one time. You
    #    can set this to any number you want but be realistic. The limit before the server
    #    times out will depend on the maximum size of the upload. I have tested this program
    #    with ASCII files up to 8MB in size successfully but that was on a particularly
    #    robust server. I recommend that you set this no higher than 5 if you are going to
    #    be using this for larger binary files such as images or executables or word docs, etc.
    #    If you remove, comment out or set this value to zero, the program will default the
    #    value to 1 file.

  # --> Tilføjet af Thomas Palm 13/3-01
$tilphp = \"http://www.ditdomæne.dk/ditphpscript.php\";
  # Angiver hvilket script denne side bliver submitted til!!
  # PHP scriptet skal checke file1-max_num_files for værdier!

$nykode  = \"<form action=\\\"$tilphp\\\" name=\\\"tilphp\\\" method=\\\"post\\\">\";
  # Koden der starter formularen... Der bliver tilføjet mere til denne senere...

#
#######################################################################################
#
#            DO NOT EDIT ANYTHING BELOW THIS LINE
#            UNLESS YOU KNOW WHAT YOU ARE DOING
#

if(($ENV{\'QUERY_STRING\'} =~ /^debug/) && !$no_debug) {
    print \"Pragma: no-cache\\nContent-type: text/html\\n\\n\";
    print \"<TITLE>PSUpload Demonstration Upload Program - Debug Mode</TITLE></HEAD><BODY BGCOLOR=\\\"#ffffff\\\" TEXT=\\\"#330066\\\" LINK=\\\"#336666\\\" ALINK=\\\"#336666\\\" VLINK=\\\"#336666\\\" BGCOLOR=\\\"#FFFFFF\\\"><FONT SIZE=\\\"2\\\" FACE=\\\"verdana, arial, helvetica\\\">\\n\";
    print \"<CENTER><B><H2>Charity Ware\'s PSUpload Program</H2></B><BR><BR><TABLE BORDER=0><TR><TD COLSPAN=2><FONT SIZE=\\\"2\\\" FACE=\\\"verdana, arial, helvetica\\\">\\n\";
    print \"<DL><DT><B>Your web root directory appears to be located at:</B><DD>$ENV{\'DOCUMENT_ROOT\'}<BR><BR><DT><B>You specified directory for storing the uploads is:</B><DD>$Data<BR><BR><DT><B>Your specified directory...</B><DD>\\n\";
    if(-d $Data) {
    print \"...appears to be a valid directory.<BR><BR>Make sure this \\$Data directory is CHMOD 777.\\n\";
    } else {
    print \"...does not appear to be a valid directory.<BR><BR>\\n\";
    unless($Data =~ /^$ENV{\'DOCUMENT_ROOT\'}/) {
        print \"The value you specified in the \\$Data variable is incorrect. Please<BR>correct your \\$Data variable and run debug again.<BR><BR>\\n\";
    }
    }
    if($Data =~ /\\/$/) {
    print \"<FONT COLOR=\\\"#FF0000\\\">NOTE: Your variable \\$Data ends with a trailing slash. Please<BR>remove this trailing slash, upload the program again<BR>and run debug once more to see if you have a valid directory.</FONT><BR><BR>\\n\";
    }
    print \"</DL><BR><BR></FONT></TD></TR><TR><TD WIDTH=\\\"50%\\\" VALIGN=\\\"TOP\\\"><FONT SIZE=\\\"2\\\" FACE=\\\"verdana, arial, helvetica\\\"><B>OS:</B><BR>$^O<BR><BR><B>Perl:</B><BR>$]</FONT></TD><TD VALIGN=\\\"TOP\\\"><FONT SIZE=\\\"2\\\" FACE=\\\"verdana, arial, helvetica\\\"><B>Installed:</B><BR>\"; my @inst = split(/\\//, $ENV{\'SERVER_SOFTWARE\'}); print join(\"<BR>\", @inst); print\"</FONT></TD></TR></TABLE><BR><BR><BR><BR><A HREF=\\\"http://www.charityware.ws/\\\">&copy; 2001, Jim Melanson</A></CENTER><BR><BR></FONT></BODY></HTML>\\n\";
} else {
    use CGI;
    $max_num_files  ||= 1;
    $Data         ||= $ENV{\'DOCUMENT_ROOT\'};
    undef @bad_extensions if @good_extensions;
    for(my $a = 1; $a <= $max_num_files; $a++) {
      $tael = $a; # --> Tilføjet af Thomas Palm 13/3-01 - Sikrer at vi har tæller værdien..
    my $req = new CGI;
    if($req->param(\"FILE$a\")) {
        my $file = $req->param(\"FILE$a\");
        my $filename = $file;
        $filename =~ s/^.*(\\\\|\\/)//;
        my $proceed_type = 0;
        if(@good_extensions) {
        foreach(@good_extensions) {
            my $ext = $_;
            $ext =~ s/\\.//g;
            if($filename =~ /\\.$ext$/) {
            $proceed_type = 1;
            last;
            }
        }
        unless($proceed_type) {
            push(@was_not_good_type, $filename);
        }
        }
        elsif(@bad_extensions) {
        $proceed_type = 1;
        foreach(@bad_extensions) {
            my $ext = $_;
            $ext =~ s/\\.//g;
            if($filename =~ /\\.$ext$/) {
            $proceed_type = 0;
            last;
            }
        }
        unless($proceed_type) {
            push(@was_a_bad_type, $filename);
        }
        } else {
        $proceed_type = 1;
        }
        if($proceed_type) {
        if(open(OUTFILE, \">$Data/$filename\")) {
            while (my $bytesread = read($file, my $buffer, 1024)) {
            print OUTFILE $buffer;
            }
            close (OUTFILE);
            push(@file_did_save, $filename);
            # --> Tilføjet af Thomas Palm 13/3-01.
            $nykode .= \"<input type=\\\"hidden\\\" name=\\\"file\".$tael.\"\\\" value=\\\"$filename\\\">\\n\";
        } else {
            push(@did_not_save, $filename);
        }
        }
        if($max_size) {
        if((-s \"$Data/$filename\") > ($max_size * 1024)) {
            push(@was_too_big, $filename);
            unlink(\"$Data/$filename\");
        }
        }
    }
    }
    $nykode .= \"</form>\"; # --> Tilføjet af Thomas Palm 13/3-01 - Afslutter vores \"fake\"form..
    $spring  = \'<script language=\"javascript\">\';
    $spring .= \'document.forms[\'tilphp\'].submit();\';
    $spring .= \'</script>\'; # Dette script submitter formen automatisk....
    print \"Pragma: no-cache\\n\";
    if($redirect && ($redirect =~ /^http\\:\\/\\//)) {
    print \"Location: $redirect\\n\\n\";
    } else {
    print \"Content-type: text/html\\n\\n\";
    print \"<HEAD><TITLE>PSUpload Results</TITLE></HEAD><BODY><FONT FACE=\\\"verdana,helvetica,arial\\\" SIZE=2><BR><BR><CENTER><B><H2>Upload Results</H2></B><HR WIDTH=\\\"65%\\\"><BR><BR>\\n\";
    if(@file_did_save) {print \"<B>The following file(s) were saved:<BR><BR>\\n\"; print join(\"<BR>\", @file_did_save); print \"<BR><BR>\\n\"; print \"$nykode\\n\"; print \"$spring\\n\";}
    if(@was_not_good_type) {print \"<B>The following file(s) were not stored as their file extension<BR>did not match any of the valid extensions specified in the program:<BR><BR>\\n\"; print join(\"<BR>\", @was_not_good_type); print \"<BR><BR>\\n\"}
    if(@was_a_bad_type) {print \"<B>The following files were not stored as their file extension<BR>are on the list of extensions not permitted for upload:<BR><BR>\\n\"; print join(\"<BR>\", @was_a_bad_type); print \"<BR><BR>\\n\"}
    if(@was_too_big) {print \"<B>The following files were not stored as their file size<BR>exceeded the maximum file size of $max_size Kb.:<BR><BR>\\n\"; print join(\"<BR>\", @was_too_big); print \"<BR><BR>\\n\"}
    if(@did_not_save) {print \"<B>The following files were not stored because the<BR>program could not open their destination file:<BR><BR>\\n\"; print join(\"<BR>\", @did_not_save);print \"<BR><BR>\\n\";
            if(!@file_did_save) {print \"<FONT COLOR=\\\"RED\\\"><B>NOTE: Check to ensure that the \\$Data variable reflects the correct<BR>absolute path to the directory these files should be store in.</B></FONT><BR><BR>\"}
    }
    print \"<BR><BR><HR WIDTH=\\\"65%\\\"><BR><A HREF=\\\"http://www.charityware.ws/psupload/psupload.shtml/\\\"><FONT COLOR=\\\"#C0C0C0\\\">&copy; 2001, Jim Melanson</FONT></A><BR></BODY></HTML>\\n\";
    }
}
Avatar billede kenneth_jakel Nybegynder
14. marts 2001 - 09:36 #10
Jeg får den her, men jeg kan ikke gennemskue om det har noget med cgi-scriptet at køre, når der står at der er fejl på serveren.


Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@flare.dk and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.



--------------------------------------------------------------------------------

Apache/1.3.14 Server at www.flare.dk Port 80



jeg vil forøvrigt gerne have dig til at modificerer yderligere hvis du gider. hvis du får 100 point mere, kan du så ikke lave det sådan at hvis jeg laver tre ekstra text-felter i formularen i HTML\'en så bliver de tre variabler der kommer ud af det, sat ind i fakeformen i CGI\'en og ført med videre til PHP-scriptet??

/Kenneth
Avatar billede Thomas Nybegynder
14. marts 2001 - 11:47 #11
3 xtra felter kan sagtens sættes ind - jeg skal bare have navnene på dem.

Hvad angår fejlen, så kigger jeg lige scriptet igennem (har måske glemt et ; eller noget et sted...) - men det er nødvendigvis ikke fejlen. Fejlen kan også være CHMOD der er sat forkert.. men det har du vel kontrolleret? (o:

Jeg er hjemme ved 15-16 tiden, så kigger jeg det lige nærmere efter...
Avatar billede Thomas Nybegynder
14. marts 2001 - 11:56 #12
Kan ikke umiddelbart finde nogle syntaks mæssige fejl.. har du kontrolleret at der ikke er mærkelige linieskift i scriptet når du cut\'n\'paster??
Avatar billede kenneth_jakel Nybegynder
14. marts 2001 - 11:56 #13
bare kald dem $dato, $overskrift og $text . jeg har sat CHMOD til 755, så det skulle være iorden.

/kenneth
Avatar billede kenneth_jakel Nybegynder
14. marts 2001 - 12:04 #14
hmm, jeg har lige tjekket...der er ingen linjeskift der er fucked up.
Avatar billede Thomas Nybegynder
14. marts 2001 - 12:10 #15
Må lige kigge på det når jeg kommer hjem....

Jeg opretter bare de 3 variabler som du har nævnt!!
Avatar billede kenneth_jakel Nybegynder
14. marts 2001 - 12:48 #16
én af mine venner kunne konstarterede følgende:

Bad name after tilphp\' at upload.cgi line 210.

/kenneth
Avatar billede Thomas Nybegynder
14. marts 2001 - 12:56 #17
ØJ!!! Du har fuldstændigt ret... Ved godt hvilken linie det er...

Linien er
$spring .= \'document.forms[\'tilphp\'].submit();\';

og skulle i stedet være
$spring .= \"document.forms[\'tilphp\'].submit();\";

Hvis du kan finde den kan du rette den og prøve om det virker så!!! (Men det giver dig selvf. ikke de 3 extra felter med)...
Avatar billede kenneth_jakel Nybegynder
14. marts 2001 - 13:13 #18
hurra - nu virker det...
men jeg ville stadig gerne have de tre x-tra felter der. (for 100 points)
/kenneth



Avatar billede Thomas Nybegynder
14. marts 2001 - 15:24 #19
Nu skulle de 3 xtra felter være med... Jeg må dog lige sige, at jeg ikke er vant til at hente mine variabler ind på den måde som de bliver brugt i scriptet, så hvis det virker så er alt fjong, ellers må du vende tilbage, så må jeg finde en anden måde at løse problemet på!!

Her er scriptet i modificeret version (endnu en gang):

#!/usr/bin/perl

#######################################################################################
#
#    PSUpload Helper (PSUpload) V2.0
#    ©2001, Jim Melanson
#    jim@perlservices.com, info@charityware.ws
#
#    Requirements:        UNIX Server, Perl5+
#    Created:        September 22nd, 2000
#    Author:         Jim Melanson, Owner and Lead Programmer
#    Contact:        www.perlservices.com, www.charityware.ws
#                Phone:        1-705-437-3283
#                Fax:        1-208-694-1613
#                E-Mail:        info@perlservices.com
#
#    This utility is distributed under the same terms as Perl itself. It may be
#    modified and utilized as you will so long as the original copyright notice
#    remains in the header and that any modifications you make are state in the
#    header along with the date of the modification and the name and email addy
#    of the person who made the modification.
#
#    Additionally, this program has been designated as Charity Ware. That means
#    that if you use the program or modify the program to use it in/with another
#    program then you are required to make a charitable donation to a charity
#    of YOUR choice in the amount of YOUR choice. We\'d appreciate your dropping
#    by Charity Ware (www.charityware.ws) to register your donation so others can
#    see who is benefiting from our work. If your too busy, drop us a line telling
#    us who benefited and how much you gave them and we\'ll post the registration
#    for you.
#
#    This program requires installation on a UNIX server running Perl4 or higher.
#
#    This program require the use of the CGI.pm module. If it is not installed
#    on your server, you can have your sysadmin obtain the latest version of CGI.pm
#    form the CPAN site at www.cpan.org
#
#    Please see the accompanying HTML demonstration file for instructions on
#    creating the upload form you will put on your HTML page.
#
#    History:
#    This program was originally written in a basic form by Mark Knickelbain. After
#    Perl Services was taken over by Jim Melanson, this utility was re-written. This
#    re-write has been based on the feedback of hundreds of users. The features
#    incorporated in the re-write were the most common requests of PSUpload Helper
#    users. Version 2.0 of this program was released on February 22nd, 2001.
#
#    It was the authors choice that PSUpload Helper 2.0 should be distributed from
#    the Charity Ware site at www.charityware.ws so that others less fortunate may
#    benefit from his efforts.
#
#######################################################################################
#
#    FINAL WORD:    Do you have comments or criticisms (constructive ones) please
#            send them to jim@perlservices.com or info@charityware.ws. This
#            library and the V2 of PSUpload Helper are the results of input
#            from end users and incorporate the most common requests.
#
#######################################################################################
#
#    CONFIGURE VARIABLES

$Data = \"/www/flare.dk/web/images\";
    #    On your server, create a directory where this program will write the files
    #    to. Make sure you CHMOD this directory to 777. If you do NOT specify a $Data
    #    directory, the program will attempt to write to the web root directory.
    #    NOTE: YOU SHOULD ALWAYS SPECIFY A DIRECTORY TO STORE THE UPLOAD

@good_extensions = (\'gif\', \'jpg\', \'jpeg\');
    #    If you want to limit the types of extension that can be uploaded, specify them
    #    here by adding them to the array. For example, if you wanted to permit only
    #    the upload of gif\'s, jpg\'s and png\'s, then you would set the above array to
    #    look like this:
    #    @good_extensions = (\'gif\', \'jpg\', \'jpeg\', \'png\');
    #

@bad_extensions = ();
    #    If you want to permit the upload of all file types with only certain exceptions,
    #     then specify those extensins in the bad_extensions array. This means that if set
    #  this array to contain .exe, .pl, .cgi files, then the program will only store a
    #    file if the extension of that file is NOT found in this array.
    #    To set the array to exclude these sample extensions, you would set it like this:
    #    @bad_extensions = (\'exe\', \'cgi\', \'pl\');
    #

    #    NOTE: If you specify both @good_extensions and @bad_extensions, then
    #    the settings in @bad_extensions will be ignored and the program will
    #    use @good_extensions as it\'s refrence.

$redirect = \"\";
    #    When the upload of files is complete, the program must print someting out on the
    #    browser screen. Set the $redirect variable to the full URL (don\'t forget the http://)
    #    that you want the person taken to once the program is finished. If you don\'t specify
    #    a URL here, the program will print out a simple upload summary page.

$max_size = 50;
    #    Set the maximum size of each file that is permitted. For example, if you only want
    #    files to be uploaded that are under 50Kb in size, set the value to:
    #    $max_size = 50;
    #    If you set the value to zero, remove it or comment it out, then the size of the
    #    uploaded file will NOT be checked.

$max_num_files = 3;
    #    You must specify the maximum number of files that can be uploaded at one time. You
    #    can set this to any number you want but be realistic. The limit before the server
    #    times out will depend on the maximum size of the upload. I have tested this program
    #    with ASCII files up to 8MB in size successfully but that was on a particularly
    #    robust server. I recommend that you set this no higher than 5 if you are going to
    #    be using this for larger binary files such as images or executables or word docs, etc.
    #    If you remove, comment out or set this value to zero, the program will default the
    #    value to 1 file.

  # --> Tilføjet af Thomas Palm 13/3-01
$tilphp = \"http://www.ditdomæne.dk/ditphpscript.php\";
  # Angiver hvilket script denne side bliver submitted til!!
  # PHP scriptet skal checke file1-max_num_files for værdier!

$nykode  = \"<form action=\\\"$tilphp\\\" name=\\\"tilphp\\\" method=\\\"post\\\">\";
  # Koden der starter formularen... Der bliver tilføjet mere til denne senere...

#
#######################################################################################
#
#            DO NOT EDIT ANYTHING BELOW THIS LINE
#            UNLESS YOU KNOW WHAT YOU ARE DOING
#

if(($ENV{\'QUERY_STRING\'} =~ /^debug/) && !$no_debug) {
    print \"Pragma: no-cache\\nContent-type: text/html\\n\\n\";
    print \"<TITLE>PSUpload Demonstration Upload Program - Debug Mode</TITLE></HEAD><BODY BGCOLOR=\\\"#ffffff\\\" TEXT=\\\"#330066\\\" LINK=\\\"#336666\\\" ALINK=\\\"#336666\\\" VLINK=\\\"#336666\\\" BGCOLOR=\\\"#FFFFFF\\\"><FONT SIZE=\\\"2\\\" FACE=\\\"verdana, arial, helvetica\\\">\\n\";
    print \"<CENTER><B><H2>Charity Ware\'s PSUpload Program</H2></B><BR><BR><TABLE BORDER=0><TR><TD COLSPAN=2><FONT SIZE=\\\"2\\\" FACE=\\\"verdana, arial, helvetica\\\">\\n\";
    print \"<DL><DT><B>Your web root directory appears to be located at:</B><DD>$ENV{\'DOCUMENT_ROOT\'}<BR><BR><DT><B>You specified directory for storing the uploads is:</B><DD>$Data<BR><BR><DT><B>Your specified directory...</B><DD>\\n\";
    if(-d $Data) {
    print \"...appears to be a valid directory.<BR><BR>Make sure this \\$Data directory is CHMOD 777.\\n\";
    } else {
    print \"...does not appear to be a valid directory.<BR><BR>\\n\";
    unless($Data =~ /^$ENV{\'DOCUMENT_ROOT\'}/) {
        print \"The value you specified in the \\$Data variable is incorrect. Please<BR>correct your \\$Data variable and run debug again.<BR><BR>\\n\";
    }
    }
    if($Data =~ /\\/$/) {
    print \"<FONT COLOR=\\\"#FF0000\\\">NOTE: Your variable \\$Data ends with a trailing slash. Please<BR>remove this trailing slash, upload the program again<BR>and run debug once more to see if you have a valid directory.</FONT><BR><BR>\\n\";
    }
    print \"</DL><BR><BR></FONT></TD></TR><TR><TD WIDTH=\\\"50%\\\" VALIGN=\\\"TOP\\\"><FONT SIZE=\\\"2\\\" FACE=\\\"verdana, arial, helvetica\\\"><B>OS:</B><BR>$^O<BR><BR><B>Perl:</B><BR>$]</FONT></TD><TD VALIGN=\\\"TOP\\\"><FONT SIZE=\\\"2\\\" FACE=\\\"verdana, arial, helvetica\\\"><B>Installed:</B><BR>\"; my @inst = split(/\\//, $ENV{\'SERVER_SOFTWARE\'}); print join(\"<BR>\", @inst); print\"</FONT></TD></TR></TABLE><BR><BR><BR><BR><A HREF=\\\"http://www.charityware.ws/\\\">&copy; 2001, Jim Melanson</A></CENTER><BR><BR></FONT></BODY></HTML>\\n\";
} else {
    use CGI;
    $max_num_files  ||= 1;
    $Data         ||= $ENV{\'DOCUMENT_ROOT\'};
    undef @bad_extensions if @good_extensions;
    for(my $a = 1; $a <= $max_num_files; $a++) {
      $tael = $a; # --> Tilføjet af Thomas Palm 13/3-01 - Sikrer at vi har tæller værdien..
    my $req = new CGI;

    $dato=$req->param(\"dato\"); # --> Tilføjet af Thomas Palm 14/3-01: Finder dato feltet
    $overskrift=$req->param(\"overskrift\"); # --> Tilføjet af Thomas Palm 14/3-01: Finder overskrift feltet
    $text=$req->param(\"text\"); # --> Tilføjet af Thomas Palm 14/3-01: Finder text feltet

    if($req->param(\"FILE$a\")) {
        my $file = $req->param(\"FILE$a\");
        my $filename = $file;
        $filename =~ s/^.*(\\\\|\\/)//;
        my $proceed_type = 0;
        if(@good_extensions) {
        foreach(@good_extensions) {
            my $ext = $_;
            $ext =~ s/\\.//g;
            if($filename =~ /\\.$ext$/) {
            $proceed_type = 1;
            last;
            }
        }
        unless($proceed_type) {
            push(@was_not_good_type, $filename);
        }
        }
        elsif(@bad_extensions) {
        $proceed_type = 1;
        foreach(@bad_extensions) {
            my $ext = $_;
            $ext =~ s/\\.//g;
            if($filename =~ /\\.$ext$/) {
            $proceed_type = 0;
            last;
            }
        }
        unless($proceed_type) {
            push(@was_a_bad_type, $filename);
        }
        } else {
        $proceed_type = 1;
        }
        if($proceed_type) {
        if(open(OUTFILE, \">$Data/$filename\")) {
            while (my $bytesread = read($file, my $buffer, 1024)) {
            print OUTFILE $buffer;
            }
            close (OUTFILE);
            push(@file_did_save, $filename);
            # --> Tilføjet af Thomas Palm 13/3-01.
            $nykode .= \"<input type=\\\"hidden\\\" name=\\\"file\".$tael.\"\\\" value=\\\"$filename\\\">\\n\";
        } else {
            push(@did_not_save, $filename);
        }
        }
        if($max_size) {
        if((-s \"$Data/$filename\") > ($max_size * 1024)) {
            push(@was_too_big, $filename);
            unlink(\"$Data/$filename\");
        }
        }
    }
    }

  # --> tilføjet af thomas palm 14/3-01 - husker de 3 særlige felter...
    $nykode .= \"<input type=\\\"hidden\\\" name=\\\"text\\\" value=\\\"$text\\\">\\n\";
    $nykode .= \"<input type=\\\"hidden\\\" name=\\\"dato\\\" value=\\\"$dato\\\">\\n\";
    $nykode .= \"<input type=\\\"hidden\\\" name=\\\"overskrift\\\" value=\\\"$overskrift\\\">\\n\";
    $nykode .= \"</form>\"; # --> Tilføjet af Thomas Palm 13/3-01 - Afslutter vores \"fake\"form..
    $spring  = \'<script language=\"javascript\">\';
    $spring .= \"document.forms[\'tilphp\'].submit();\";
    $spring .= \'</script>\'; # Dette script submitter formen automatisk....
    print \"Pragma: no-cache\\n\";
    if($redirect && ($redirect =~ /^http\\:\\/\\//)) {
    print \"Location: $redirect\\n\\n\";
    } else {
    print \"Content-type: text/html\\n\\n\";
    print \"<HEAD><TITLE>PSUpload Results</TITLE></HEAD><BODY><FONT FACE=\\\"verdana,helvetica,arial\\\" SIZE=2><BR><BR><CENTER><B><H2>Upload Results</H2></B><HR WIDTH=\\\"65%\\\"><BR><BR>\\n\";
    if(@file_did_save) {print \"<B>The following file(s) were saved:<BR><BR>\\n\"; print join(\"<BR>\", @file_did_save); print \"<BR><BR>\\n\"; print \"$nykode\\n\"; print \"$spring\\n\";}
    if(@was_not_good_type) {print \"<B>The following file(s) were not stored as their file extension<BR>did not match any of the valid extensions specified in the program:<BR><BR>\\n\"; print join(\"<BR>\", @was_not_good_type); print \"<BR><BR>\\n\"}
    if(@was_a_bad_type) {print \"<B>The following files were not stored as their file extension<BR>are on the list of extensions not permitted for upload:<BR><BR>\\n\"; print join(\"<BR>\", @was_a_bad_type); print \"<BR><BR>\\n\"}
    if(@was_too_big) {print \"<B>The following files were not stored as their file size<BR>exceeded the maximum file size of $max_size Kb.:<BR><BR>\\n\"; print join(\"<BR>\", @was_too_big); print \"<BR><BR>\\n\"}
    if(@did_not_save) {print \"<B>The following files were not stored because the<BR>program could not open their destination file:<BR><BR>\\n\"; print join(\"<BR>\", @did_not_save);print \"<BR><BR>\\n\";
            if(!@file_did_save) {print \"<FONT COLOR=\\\"RED\\\"><B>NOTE: Check to ensure that the \\$Data variable reflects the correct<BR>absolute path to the directory these files should be store in.</B></FONT><BR><BR>\"}
    }
    print \"<BR><BR><HR WIDTH=\\\"65%\\\"><BR><A HREF=\\\"http://www.charityware.ws/psupload/psupload.shtml/\\\"><FONT COLOR=\\\"#C0C0C0\\\">&copy; 2001, Jim Melanson</FONT></A><BR></BODY></HTML>\\n\";
    }
}
Avatar billede kenneth_jakel Nybegynder
14. marts 2001 - 20:48 #20
Superfedt

Nu virker alt som det skal. Tak for hjælpen.

accepter http://www.eksperten.dk/spm/56817 så du kan få dine sidste 100 point.

/kenneth
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester