Hi All, latest
You are welcome, I dont know whether I set correctly all perl, apache and html as my perl 5.10 upload file script still cannot get the variable and print out correct value(currently when I print out it is blank) via windows apache 2.2.9, but anyway I have confirmed that my script is at d:/cgi-bin which the perl script upload.pl resides, as I used section d) perl script upload2.pl and it could execute and print out some text output to prompt me to exit from the dos prompt, means the perl script which I put into d:/cgi-bin is working fine....
Been trying for past 2 weeks, very demoralized.... Kindly advise which other parts could be wrong??? Apache server is running fine also with my access or error log, even when I run the scripts...
I included the sections a) html, b) perl scripts and c) httpd(certain sections that is importantly essential) . Please kindly see if the perl script or apache httpd config is wrong?
Thanks in Advance!!
Cheers...
Andrew
a) html
----------
-
</html>
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-
<title>File Upload</title>
-
</head>
-
<body>
-
<form action="cgi-bin/upload.pl" 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>
-
b) perl script upload.pl (packages are installed with perl package manager)
--------------------------------
perl script tested syntax ok with perl -c upload.pl
-
#!c:/perl/bin/perl.exe -w
-
package HelloWorld;
-
-
use test-strict;
-
use CGI;
-
use CGI::Carp qw ( fatalsToBrowser );
-
use File::Basename;
-
use HTML::Debug;
-
-
$CGI::POST_MAX = 1024 * 5000;
-
my $safe_filename_characters = "a-zA-Z0-9_.-";
-
my $upload_dir = "d:/uploaded";
-
-
my $query = new CGI;
-
my $filename = $query->param("photo");
-
my $email_address = $query->param("email_address");
-
-
-
-
if ( !$filename )
-
{
-
print $query->header ( );
-
print "There was a problem uploading your photo (try a smaller file).";
-
print "CGI - $CGI::POST_MAX";
-
print "safe - $safe_filename_characters ";
-
print "photo - $filename ";
-
-
-
print "Press the ENTER key to exit program ...";
-
$pause = <STDIN>; #Like a PAUSE statement in DOS .bat files
-
-
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;
-
-
print "Press the ENTER key to exit program2 ...";
-
$pause = <STDIN>; #Like a PAUSE statement in DOS .bat files
-
-
exit;
-
}
-
else
-
{
-
die "Filename contains invalid characters";
-
print "Press the ENTER key to exit program3 ...";
-
$pause = <STDIN>; #Like a PAUSE statement in DOS .bat files
-
-
exit;
-
}
-
-
my $upload_filehandle = $query->upload("photo");
-
-
open ( UPLOADFILE, ">$upload_dir/$filename" ) or die "$!";
-
binmode UPLOADFILE;
-
-
while ( <$upload_filehandle> )
-
{
-
-
print "Press the ENTER key to exit program4 ...";
-
$pause = <STDIN>; #Like a PAUSE statement in DOS .bat files
-
-
exit;
-
-
print UPLOADFILE;
-
}
-
-
close UPLOADFILE;
-
c) httpd configuration (the default and Re-configured portion, essentially needed)
----------------------------------------------------------------------
#DEFAULTS
# ScriptAlias: This controls which directories contain server scripts.
# ScriptAliases are essentially the same as Aliases, except that
# documents in the target directory are treated as applications and
# run by the server when requested rather than as documents sent to the
# client. The same rules about trailing "/" apply to ScriptAlias
# directives as to Alias.
#
ScriptAlias /cgi-bin/ "D:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/"
</IfModule>
<IfModule cgid_module>
#
# ScriptSock: On threaded servers, designate the path to the UNIX
# socket used to communicate with the CGI daemon of mod_cgid.
#
#Scriptsock logs/cgisock
</IfModule>
#
# "D:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "D:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
I configured
----------------------
# i) This should be changed to whatever you set DocumentRoot to.
#
<Directory "D:/Program Files/Apache Software Foundation/Apache2.2/htdocs">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwner Match ExecCGI MultiViews
#
# Note that "MultiViews " must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
#
http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks ExecCGI
# ii)
# AddHandler allows you to map certain file extensions to "handlers":
# actions unrelated to filetype. These can be either built into the server
# or added with the Action directive (see below)
#
# To use CGI scripts outside of ScriptAliased directories:
# (You will also need to add "ExecCGI" to the "Options" directive.)
#
AddHandler cgi-script .cgi .pl
D) perl script upload.pl(to print out the things only)
-
print "Press the ENTER key to exit program ...";
-
$pause = <STDIN>; #Like a PAUSE statement in DOS .bat files
-
-
exit;
-