I've been trying to construct a cgi perl upload script to upload PowerPoint files to a folder and have run into a brick wall. Specifically, it is a 500 Internal Server Error. I successfully tested the setup on my home server (running Apache 2.2 on Windows with Strawberry Perl installed).
I've tried changing the permissions on all the files and folders to 777, but I still consistently receive the following error:
" Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@adamspowerpoint.x10hosting.com 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.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
"
Here's the code for the index.html file which references a cgi script which does the actual uploading:
And here is the cgi perl script code within upload.cgi:
Does anyone know what's wrong with my coding or is there something wrong with the server? (starka.x10hosting.com)
This is the URL to the upload page: http://adamspowerpoint.x10hosting.com/uptest/ (The rest of the site is password-protected).
I've tried changing the permissions on all the files and folders to 777, but I still consistently receive the following error:
" Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@adamspowerpoint.x10hosting.com 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.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
"
Here's the code for the index.html file which references a cgi script which does the actual uploading:
Code:
<!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>File Upload</title>
</head>
<body>
<form action="upload.cgi" method="post"
enctype="multipart/form-data">
<p>Photo to Upload: <input type="file" name="photo" /></p>
<p>Your Email Address: <input type="text" name="email_address" /></p>
<p><input type="submit" name="Submit" value="Submit Form" /></p>
</form>
</body>
</html>
And here is the cgi perl script code within upload.cgi:
Code:
#!/usr/bin/perl
use strict;
use CGI;
use CGI::Carp qw ( fatalsToBrowser );
use File::Basename;
$CGI::POST_MAX = 1024 * 2000;
my $safe_filename_characters = "a-zA-Z0-9_.-";
my $upload_dir = "2010";
my $query = new CGI;
my $filename = $query->param("file");
my $email_address = $query->param("email_address");
if ( !$filename )
{
print $query->header ( );
print "There was a problem uploading 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("file");
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>Thanks!</title>
<style type="text/css">
img {border: none;}
</style>
</head>
<body>
<p>Thanks for uploading your file!</p>
<p>Your email address: $email_address</p>
<p>Your photo:</p>
<!--<p><img src="/2010/$filename" alt="file" /></p> -->
</body>
</html>
END_HTML
Does anyone know what's wrong with my coding or is there something wrong with the server? (starka.x10hosting.com)
This is the URL to the upload page: http://adamspowerpoint.x10hosting.com/uptest/ (The rest of the site is password-protected).