Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12
  1. #1
    Junior Member lemusa's Avatar
    Join Date
    Jan 2009
    Location
    Christchurch, NZ
    Posts
    9
    Member #
    18091
    not sure im supposed to post this here so move it if it isnt please

    when tryin to upload files to my website from the about page i get the error...

    Software error:
    Can't find string terminator "END_HTML" anywhere before EOF at upload.cgi line 49.

    Script is below

    #!/usr/bin/perl -wT

    use strict;
    use CGI;
    use CGI::Carp qw ( fatalsToBrowser );
    use File::Basename;

    $CGI::POST_MAX = 1024 * 5000;
    my $safe_filename_characters = "a-zA-Z0-9_.-";
    my $upload_dir = "/uploads";

    my $query = new CGI;
    my $filename = $query->param("file");

    if ( !$filename )
    {
    print $query->header ( );
    print "There was a problem uploading your file (try a smaller file).";
    exit;
    }

    my ( $name, $path, $extension ) = fileparse ( $filename, '\..*' );
    $filename = $name . $extension;
    $filename =~ tr/ /_/;
    $filename =~ s/[^$safe_filename_characters]//g;

    if ( $filename =~ /^([$safe_filename_characters]+)$/ )
    {
    $filename = $1;
    }
    else
    {
    die "Filename contains invalid characters";
    }

    my $upload_filehandle = $query->upload("photo");

    open ( UPLOADFILE, ">$upload_dir/$filename" ) or die "$!";
    binmode UPLOADFILE;

    while ( <$upload_filehandle> )
    {
    print UPLOADFILE;
    }

    close UPLOADFILE;

    print $query->header ( );
    print <<END_HTML
    ;
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Upload Successful</title>
    <style type="text/css">
    img {border: none;}
    </style>
    </head>
    <body>
    <p>Thanks for contributing!</p>
    </body>
    </html>
    END_HTML


  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    The semi colon below the line print <<END_HTML should be at the end of that line.

    Try this
    Code:
    print <<END_HTML;
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Upload Successful</title>
    <style type="text/css">
    img {border: none;}
    </style>
    </head>
    <body>
    <p>Thanks for contributing!</p>
    </body>
    </html>
    END_HTML

  4. #3
    Junior Member lemusa's Avatar
    Join Date
    Jan 2009
    Location
    Christchurch, NZ
    Posts
    9
    Member #
    18091
    k im tryin a new code, same thing just updated

    get this error now
    fileparse(): need a valid pathname at upload.cgi line 36

    new code below...

    #!/usr/bin/perl -T

    use strict;
    use warnings;
    use CGI;
    use CGI::Carp qw/fatalsToBrowser/;
    use File::Basename;

    # set the maximum limit for file uploads
    $CGI::POST_MAX = 1024 * 5000; #adjust as needed (1024 * 5000 = 5MB)

    # change to 1 (one) to disable file uploads
    $CGI:ISABLE_UPLOADS = 0; #1 disables uploads, 0 enables uploads

    my $query = new CGI;

    unless ($CGI::VERSION >= 2.47) {
    print $query->header(),
    $query->start_html(),
    'Your version of CGI.pm is too old. You must have verison 2.47 or higher to use this script.',
    $query->end_html;
    exit(0);
    }

    my $upload_dir = "uploads";

    # a list of valid characters that can be in filenames
    my $filename_characters = 'a-zA-Z0-9_.-';

    my $file = $query->param("photo");
    my $email_address = $query->param("email_address");

    # get the filename and the file extension
    # this could be used to filter out unwanted filetypes
    # see the File::Basename documentation for details
    my ($filename,undef,$ext) = fileparse($file,qr{\..*});

    # convert spaces to underscores "_"
    $filename =~ tr/ /_/;

    # remove illegal characters
    $filename =~ s/[^$filename_characters]//g;

    # append extension to filename
    $filename .= $ext;

    # satisfy taint checking
    if ($filename =~ /^([$filename_characters]+)$/) {
    $filename = $1;
    }
    else{
    print $query->header(),
    $query->start_html(),
    'The filename is not valid. Filenames can only contain these characters: $filename_characters',
    $query->end_html;
    exit(0);
    }

    my $upload_filehandle = $query->upload("photo");


    open (UPLOADFILE, ">$upload_dir/$filename") or die "$!";
    binmode UPLOADFILE;
    while ( <$upload_filehandle> ) {
    print UPLOADFILE;
    }
    close UPLOADFILE;

    print $query->header(),
    $query->start_html(-title=>'Upload Successful'),
    $query->p('Thanks for uploading your photo!'),
    $query->p("Your email address: $email_address"),
    $query->p("Your photo $filename:"),
    $query->img({src=>"../uploads/$filename",alt=>''}),
    $query->end_html;

  5. #4
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Why not see if the code I posted works and then take it from there? Switching from one code snippet to another is not a good idea, your understanding of the language is not developing at all.

    Anyway, the line my ($filename,undef,$ext) = fileparse($file,qr{\..*}); is probably referencing a file that does not exist, or poorly formatted filename.

  6. #5
    Junior Member lemusa's Avatar
    Join Date
    Jan 2009
    Location
    Christchurch, NZ
    Posts
    9
    Member #
    18091
    sorry i did try the code u posted (should of said that) i found this code while searching for answers and it was recommended as a good replacement

  7. #6
    Senior Member diddy's Avatar
    Join Date
    Jun 2008
    Location
    Sydney, Australia
    Posts
    502
    Member #
    16955
    Try bfsog's code and see if it works. If it does, use it (if it works, then why search then net to find another way?). If it doesn't, come back here and ask for help. Might save time rather than researching it on the net.

  8. #7
    Junior Member lemusa's Avatar
    Join Date
    Jan 2009
    Location
    Christchurch, NZ
    Posts
    9
    Member #
    18091
    im happy with the code im using, its all workin fine now,

    i always look around for answers because i pick up little bits of info here and ther eand get the broader picture

    you guys are quick to reply though

  9. #8
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,717
    Member #
    5580
    Liked
    718 times
    There is nothing wrong with Perl. In fact, Perl is great ... (or CGI as people call it).

    ... but, you might find more support and examples of PHP scripting.
    that might end up being more beneficial to a novice programmer.


  10. #9
    Junior Member lemusa's Avatar
    Join Date
    Jan 2009
    Location
    Christchurch, NZ
    Posts
    9
    Member #
    18091
    im a bit of mess really cos i have interest in lots of different scripts but only go as far as learning what i need to for my website

    with the exception of html and css im pretty novice

    sometimes i look for a quick easy fix like i did with this particular code

    so php can do what this particular perl script can?

  11. #10
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,717
    Member #
    5580
    Liked
    718 times
    PHP can do the same thing, but if your Perl script is working good,
    keep using it. Both server-side scripting languages have their advantages
    and disadvantages. It's even possible to use both if you really want to.

    Example, for photo processing, I like to use Perl along with Imagemagick
    instead of PHP along with GD. I think Imagemagick does a better job of
    resizing photos (the quality is better).

    I like using MySQL with PHP ... much easier than MySQL with Perl.

    It's really just a personal preference type of thing.
    This topic could cause a lot of arguing one way or the other, but to each their own.



Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 09:27 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com