CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Advanced:
Image Upload $ext



Jun 23, 2009, 4:42 PM

Post #1 of 3 (2233 views)
Image Upload $ext Can't Post

KevinR, in your image upload script, you place comments that talk to testing for file extensions. In another of your posts, you provide sample coding for testing for file extensions. When I put the pieces together and run the script, it uploads a .jpg image perfectly. If I try to upload a .gif, I get an Internal Server Error. If I remove the exit(0); coding, I then get "The XML page cannot be displayed ." I've been reading my Perl manula and working this script for hours. It is indeed time to ask you. Here's the portion of the image upload script that applies.

my $file = $query->param("photo") or error('No file selected for upload.') ;
$file =~ tr/\\/\//;

# file extension testing addition next

my @ext_list = qw(jpeg jpg);
my ($filename,undef,$ext) = fileparse($file,@ext_list);
unless ($ext) {
print "Invalid file extension";

# 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{\..*});


Jun 23, 2009, 6:20 PM

Post #2 of 3 (2227 views)
Re: [razman] Image Upload $ext [In reply to] Can't Post

More than likely the problem is that your script has not printed a complete set of http headers before trying to print other output to the browser, like this line:

print "Invalid file extension";

If you are using the CGI module (OO interface like your code) that can be as simple as:

print $query->header(); 
print "Invalid file extension";

although since it is html you might want to add some markup:

print $query->header(), $query->start_html(), 
$query->h1("Invalid file extension"),

Keep in mind, that is a really simple example.


Jun 24, 2009, 8:00 AM

Post #3 of 3 (2222 views)
Re: [razman] Image Upload $ext [In reply to] Can't Post

I understand. Thank you. Rich


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives