Hi All,
my html code is sno 1) and perl code is sno 2).
a) I tried to print $filename and it cant print out the value, only blank was displayed, and the file could not be uploaded. And it didnt display the html after the perl script executed. Using perl 5.1 and apache 2.2.9 version(apache installed and run without any errors and no warning, perl tested fine)
b) Also, when i clicked the html code to submit the upload of the file, the browser would prompt me to open the perl script, and not it let run in the background which I expected it to be.
Kindly assist!!
Thanks,
Andrew
1) html code - tml>
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-
<title>File Upload</title>
-
</head>
-
<body>
-
<form action="/perl/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>
2) - #!d:\perl\bin\perl.exe -w
-
package HelloWorld;
-
-
use test-strict;
-
use CGI;
-
#use CGI::Carp-Debug qw ( fatalsToBrowser );
-
#use File::Basename-Object;
-
-
$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;
-
}
-
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;
-
<html>
-
<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 photo!</p>
-
<p>Your email address: $email_address</p>
-
<p>Your photo:</p>
-
<p><img src="/upload/$filename" alt="Photo" /></p>
-
</body>
-
</html>
-
END_HTML
-
-
-
-
#exit;
66 8089
I'm not sure which tutorial you read, but this is wrong: - action="/perl/bin/upload.pl"
that is the typical machine path to perl, that needs to be the URI of the perl script: - action="cgi-bin/upload.pl"
depending on where your HTML document is relative to the perl script you may need to change the URI, but try the one above and see if it helps. Assumes your script is in the cgi-bin, if not change the URI accordingly.
Your perl script looks like it will abort here: - my ( $name, $path, $extension ) = fileparse ( $filename, '\..*' );
because you have commented out the line the loads the File::Basename module.
Also make sure your apache server is confugured to run CGI scripts. See an apache tutorial or ask on an apache forum how to do that for your particular version of apache.
also make sure you have permission to write and read from: - my $upload_dir = "d:\uploaded";
also that would be the wrong dir to upload to,
must be at least in your apache website htdocs folder under the upload folder.
according to: - <img src="/upload/$filename" alt="Photo" />
-
Hi Pals,
Thanks! I will try them out. Cheers...
Best Rgds,
Andrew
Hi All,
I am still facing problem as the perl script is not activated by CGI. How to configure the CGI correctly? Kindly assist. The CGI conf what exactly needs to take note?
Cheers...
Andrew
Hi All,
I am still facing problem as the perl script is not activated by CGI. How to configure the CGI correctly? Kindly assist. The CGI conf what exactly needs to take note?
Cheers...
Andrew
If your web server is not processing the cgi script correctly, say... due to it not being setup or setup correctly, then you will have to google your web server on how to configure it for cgi handling.
Regards,
Jeff
Hi All,
I feel this is very good reference to my questions previously, anyway thank you also very much for your reply.
Cheers...
Hi All,
Please refer to the link below.
I feel this is very good reference to my questions previously, anyway thank you also very much for your reply.
http://www.mydigitallife.info/2005/10/17/install-setup-and-configure-cgi-and-perl-in-windows-xp/
Cheers...
Hi All,
Please refer to the link below.
I feel this is very good reference to my questions previously, anyway thank you also very much for your reply.
http://www.mydigitallife.info/2005/10/17/install-setup-and-configure-cgi-and-perl-in-windows-xp/
Cheers...
thanks for leaving a answer to the question much appreciated.
Thank You.
thanks for leaving a answer to the question much appreciated.
Thank You.
Hi...
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...
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 SymLinksifOwnerMatch 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;
-
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 SymLinksifOwnerMatch 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;
-
msn id for contact : EMAIL REMOVED
Cheers.. please feel free to contact me...
hobby for perl and other interface programming..
Ok, here it is:
1. You REALLY need to read the site Posting Guidelines. You need to know what is expected when posting.
2. That said, PLEASE USE CODE TAGS!! I just fixed more code postings in one thread than one should have to. They are required and not optional!
3. Email addresses and personal URLs are not allowed in the forums. This is for your protection.
Please read the guidelines!! This will be the only warning on these issues.
Regards,
Jeff (Moderator)
Hi Jeff,
Thanks. Ok will take note.
Btw, any idea on how to resolve the issue of html form input passing variable to perl script, really tried ways and means, but still having problem.. I will try code tags in future(not really sure what is meant, but i will use
to see it you are referring to this. Thanks.
Make use of the available formatting tags in the forum Use CODE tags around your code unless you are posting a single line of code in which case it is acceptable to omit them: - ..C like code goes here..
This will preserve white space and use a mono-spaced font making the code easier to read.
Cheers...
Andrew
I have confirmed that my script is at d:/cgi-bin which the perl script upload.pl resides
the script should be in the cgi-bin folder that is in the apache folder in the web root folder. Not sure what its all called with your version of apache, but generally something like:
c:/blahblah......apache/htdocs/cgi-bin
and your html file would be in the htdocs folder, which is the web root folder which is localhost (127.0.0.1). Now your version of apache might not be exactly like that so you may need to determine which is the web root folder.
So you start apache, then open a web browser and enter in the address box:
http://localhost/yourpage.html
where yourpage.html is the html document with the form code.
Hi Sir,
Thanks.! I think I got closer, because i placed testing.html under directory
D:\Program Files\Apache Software Foundation\Apache2.2\htdocs
and upload.pl under directory
D:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin
When i type http://127.0.0.1/testing.html, I CAN SEE the html input form NOW :)) THANKS. However, I CANT call the script as the website http automatically pointed to http://127.0.0.1/cgi-bin/upload.pl now.
It gives apache error 403, I checked the folder D:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin again and again it is READ-ONLY :| , although I can copy script into it, I cant run the script as it is read-only(not sure is this the problem, definitely getting nearby, but cant pinpoint exactly where wrong...
Getting closer. Thanks again Sir...
Andrew
ANY IDEA why the apache still cant pass the variable into perl script? Thanks in advance... Kindly assist. Cheers...
403 means the document can't be found. If the html file is in the htdocs folder and the perl script (upload.pl) is in the cgi-bin folder (that is itself in the htdocs folder) and the action of the form is action="cgi-bin/upload.pl" then I don't know why it is not working. When I check the property of a perl script on my Windows computer its "archive" and the script runs fine. I changed it to read-only and it still worked fine. Are you sure the perl script is in the correct cgi-bin folder? (htdocs/cgi-bin) and the name is upload.pl?
403 means the document can't be found. If the html file is in the htdocs folder and the perl script (upload.pl) is in the cgi-bin folder (that is itself in the htdocs folder) and the action of the form is action="cgi-bin/upload.pl" then I don't know why it is not working. When I check the property of a perl script on my Windows computer its "archive" and the script runs fine. I changed it to read-only and it still worked fine. Are you sure the perl script is in the correct cgi-bin folder? (htdocs/cgi-bin) and the name is upload.pl?
Hi Sir,
Yes, the upload.pl script resides in D:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin. I can show some output using http://127.0.0.1/cgi-bin/upload.pl
However I could not find this directory htdocs/cgi-bin at all... D:\Program Files\Apache Software Foundation\Apache2.2\htdocs is what I found which contains apache default html file index.html and I put testing.html in it which I can link using http://127.0.0.1/testing.html
Any else I needed to set correctly?
Thanks in advance,
Andrew
1. make sure your .html files are in:
D:\Program Files\Apache Software Foundation\Apache2.2\htdocs
2. make sure your .cgi .pl files are in:
D:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin
3. make sure your action in your html file form is
[HTML]<form action="/cgi-bin/update.pl" method=post>[/HTML]
also for your apache config it sure be - ScriptAlias /cgi-bin/ "D:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin\"
-
-
<Directory "D:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin">
-
AllowOverride None
-
Options FollowSymLinks ExecCGI
-
Order allow,deny
-
Allow from all
-
</Directory>
Hi Sir,
Yes, the upload.pl script resides in D:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin. I can show some output using http://127.0.0.1/cgi-bin/upload.pl
However I could not find this directory htdocs/cgi-bin at all... D:\Program Files\Apache Software Foundation\Apache2.2\htdocs is what I found which contains apache default html file index.html and I put testing.html in it which I can link using http://127.0.0.1/testing.html
Any else I needed to set correctly?
Thanks in advance,
Andrew
I'm not familair with how Apache 2.2 is setup so maybe there is no htdocs/cgi-bin folder. See Icecracks post.
Hi Kelvin,
Thanks!
So many different, which one need to focus on?
Thanks again...
Andrew
Hi Kelvin,
Thanks!
So many different sections, which one need to focus on?
Thanks again...
Andrew
Hi Kelvin,
Thanks!
So many different sections, which one need to focus on?
Thanks again...
Andrew
have you read my post above ??
hi Kelvin,
I will try, realised that icecrack is the user in this forum. I missed out his points, will try out. Also for forum you mentioned.
Quote :
You can also read the manual/documentation:
http://httpd.apache.org/docs/2.2/
Which section in this website url I need to focus on? As there are so many sections...
Thanks and Best Rgds,
Andrew
If all you want to do is test your perl scripts as CGI applications you can probably skip reading the apache manual/documentation.
My name is:
K-e-v-i-n
not:
K-e-l-v-i-n
Hi Kevin,
Thanks. Sorry for the mis spelling.
I just want to make sure when i input some forms variables like filename and email, they got passed by the apache server to the perl script(which it is not running now). Does the apache documentation you provided help? or we dont need to go the the extent to read at the moment,
Thanks in advance again buddy,
Cheers...
Andrew
Hi Kevin,
Thanks. Sorry for the mis spelling.
I just want to make sure when i input some forms variables like filename and email, they got passed by the apache server to the perl script(which it is not running now). Does the apache documentation you provided help? or we dont need to go the the extent to read at the moment,
Thanks in advance again buddy,
Cheers...
Andrew
If you don't know how to start and stop the server you could read those sections. If all you want is to test your perl scripts in a CGI environment, you don't have to read any of the apache documentation.
Hi Kevin,
Thanks for pointing out Icecrack's post on upload dir, I placed this upload directory under D:\Program Files\Apache Software Foundation\Apache2.2\htdocs and when I typed url 127.0.0.1/uploaded/ the directory showed the upload folder out neatly.(wonderful!, one step towards setting up the web)
The httpd config is not changed since the last time I posted, so is the html script(see section a below), but the perl script(see section b) I have changed to below changing the upload directory blackslash to forward slash like in below perl script(not sure if the pathing and directories are correct now?) :
HOWEVER, when I try to upload the files, using upload.pl below, the apache error come out as below :
[Sat Oct 04 03:15:04 2008] [error] [client 127.0.0.1] Premature end of script headers: upload.pl, referer: http://127.0.0.1/testing.html, the webpage result display showed internal server error.
Not if html is wrong or perl script or Even apache is wrong... But I JUST need to pass the variable from html to perl script to print out in dos prompt via apache, it is so frustrating for newbie as I tried various method... Kindly assist.
Section :
a) -
</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)
change this to the full path (whatever it is): - my $upload_dir = "c:/blah/blah/blah/uploaded";
see if that helps.
What are all the "$pause = <STDIN>" lines for?
It would pause the dos prompt output to stall instead of exiting so quickly that I cant see what is happening. Then if any keyboard key is press, the dos prompt ouput to close gracefully. cheers..
Hi Kevin / all,
This website which I modified my script from is below url a), still cant :|||, kindly assist...
a) http://www.sitepoint.com/article/uploading-files-cgi-perl/2/
section b another script is alternative which is very similar(did not use this, see end of this thread)
b) http://bytes.com/forum/thread672398.html
Thanks,
Andrew
It would pause the dos prompt output to stall instead of exiting so quickly that I cant see what is happening. Then if any keyboard key is press, the dos prompt ouput to close gracefully. cheers..
But you are running this as a CGI no?
Hi Kevin / all,
This website which I modified my script from is below url a), still cant :|||, kindly assist...
a) http://www.sitepoint.com/article/uploading-files-cgi-perl/2/
section b another script is alternative which is very similar(did not use this, see end of this thread)
b) http://bytes.com/forum/thread672398.html
Thanks,
Andrew
Ah, that old article on sitepoint. The article you see now is actully the article updated with many suggestion I urged the author to include. The original article was terrible.
My own article is here: http://bytes.com/forum/thread672398.html
You will notice similarities because Matt Doyle used quite a lot of my suggestions in his article but gave me no credit.
Hi Kevin Guru Teacher,
Thanks!, if I can make it I wont forget you!!! My name is Andrew Se Bee Teck. Will try your script first...
Cheers...
Andrew
Hi Guru Teacher,
Tried your script, and modified some naming and parameters and minor details, it worked. You are genius!!! Thank you, thank you and thank you again!!!!
Cheers...
Andrew
Hi Guru Teacher Kevin,
Btw, do you have any script and html example for downloading files?
Cheers...
Andrew
Would you please provide more details?
Hi Guru Teacher Kevin,
Btw, do you have any script and html example for downloading files?
Cheers...
Andrew
I have an article in the works in regards to that type of script. But its not ready yet.
Hi All,
Found one site for downloading script. Cheers..
http://www.sitepoint.com/print/file-download-script-perl/
Andrew
Hi All,
Found one site for downloading script. Cheers..
http://www.sitepoint.com/print/file-download-script-perl/
Andrew
Do not use that script, it is very insecure. Use this one instead: - #!/usr/bin/perl -T
-
-
use strict;
-
use warnings;
-
use CGI;
-
# Uncomment the next line only for debugging the script.
-
#use CGI::Carp qw/fatalsToBrowser/;
-
-
# the path to where the downloadable files are.
-
# prefereably this should be above the web root folder.
-
my $path_to_files = '/home/you/downloads';
-
-
my $q = CGI->new;
-
-
my $file = $q->param('file') or error('Error: No file selected.');
-
-
# here we untaint the filename and make sure there are no characters like /
-
# in the name that could be used to download files from any folder on the website.
-
# personally I don't even recommend you pass filenames to the script, but that
-
# gets too complicated for a simple example of a download script.
-
if ($file =~ /^(\w+[\w.-]+\.\w+)$/) {
-
$file = $1;
-
}
-
else {
-
error('Error: Unexpected characters in filename.');
-
}
-
-
if ($file) {
-
download($file) or error('Error: an unknown error has occured. Try again.');
-
}
-
-
sub download {
-
-
# Uncomment the next line only for debugging the script
-
#open(DLFILE, '<', "$path_to_files/$file") or die "Can't open file '$path_to_files/$file' : $!";
-
-
# Comment the next line if you uncomment the above line
-
open(DLFILE, '<', "$path_to_files/$file") or return(0);
-
-
# this prints the download headers with the file size included
-
# so you get a progress bar in the dialog box that displays during file downlaods.
-
print $q->header(-type => 'application/x-download',
-
-attachment => $file,
-
'Content-length' => -s "$path_to_files/$file",
-
);
-
-
binmode DLFILE;
-
print while <DLFILE>;
-
close (DLFILE);
-
return(1);
-
}
-
-
# This is a very generic error page. You should make a better one.
-
sub error {
-
print $q->header(),
-
$q->start_html(-title=>'Error'),
-
$q->h1($_[0]),
-
$q->end_html;
-
exit(0);
-
}
See posts number 40 and 41 in this thread for explanations why it should not be used: http://www.sitepoint.com/forums/showthread.php?t=114880
I post as KevinR on the sitepoint perl forum, the comments in post number 40, 41, and the code in post 42 (same as above) are mine.
Hi Kevin,
Thanks. Btw, I used back the old html form and executed your script. Did not work, checked that the script is what you have provided. Maybe variable is not standard, still checking...
http://127.0.0.1/cgi-bin/solid.pl?file=0001.jpg+%5B5%5D&B1=Submit is the url query that the script generated. And the html result printed out is
"Error: Unexpected characters in filename."
Thanks and Best Rgds,
Andrew
a) modified html
============ -
<html><head>
-
<title>Download Page</title>
-
</head>
-
<body>
-
<form action="/cgi-bin/solid.pl">
-
<p>
-
<select size="1" name="file">
-
<option value="0001.jpg [5]">File One
-
</option>
-
<option value="file.zip">File Two
-
</option>
-
</p>
-
</select>
-
<input type="submit" value="Submit" name="B1">
-
</form>
-
</body>
-
</html>
-
-
b) modified script
============= -
-
#!c:\perl\bin\perl.exe -T
-
#!/usr/bin/perl -T
-
-
use strict;
-
use warnings;
-
use CGI;
-
# Uncomment the next line only for debugging the script.
-
#use CGI::Carp qw/fatalsToBrowser/;
-
-
# the path to where the downloadable files are.
-
# prefereably this should be above the web root folder.
-
my $path_to_files = 'D:/Program Files/Apache Software Foundation/Apache2.2/htdocs/downloads';
-
-
my $q = CGI->new;
-
-
print " q- $q";
-
-
my $file = $q->param('file') or error('Error: No file selected.');
-
-
# here we untaint the filename and make sure there are no characters like /
-
# in the name that could be used to download files from any folder on the website.
-
# personally I don't even recommend you pass filenames to the script, but that
-
# gets too complicated for a simple example of a download script.
-
if ($file =~ /^(\w+[\w.-]+\.\w+)$/) {
-
$file = $1;
-
-
print " file - $file ";
-
-
-
-
}
-
-
-
-
-
-
-
-
else {
-
error('Error: Unexpected characters in filename.');
-
}
-
-
if ($file) {
-
download($file) or error('Error: an unknown error has occured. Try again.');
-
}
-
-
sub download {
-
-
# Uncomment the next line only for debugging the script
-
#open(DLFILE, '<', "$path_to_files/$file") or die "Can't open file '$path_to_files/$file' : $!";
-
-
# Comment the next line if you uncomment the above line
-
open(DLFILE, '<', "$path_to_files/$file") or return(0);
-
-
# this prints the download headers with the file size included
-
# so you get a progress bar in the dialog box that displays during file downlaods.
-
print $q->header(-type => 'application/x-download',
-
-attachment => $file,
-
'Content-length' => -s "$path_to_files/$file",
-
);
-
-
binmode DLFILE;
-
print while <DLFILE>;
-
close (DLFILE);
-
return(1);
-
}
-
-
# This is a very generic error page. You should make a better one.
-
sub error {
-
print $q->header(),
-
$q->start_html(-title=>'Error'),
-
$q->h1($_[0]),
-
$q->end_html;
-
exit(0);
-
}
-
-
Hi Kevin Guru,
I tried out the same html and your script, it works perfectly fine, I think when I download the sample html code below, after the 0001.jpg there are invalid characters [5] before the >file one, and it is affecting the whole script. So therefore after I remove it. It is fine now. The file is downloaded to temp location.
Cheers...
Andrew
Correct html code(need to have file under download directory.. -
<html><head>
-
<title>Download Page</title>
-
</head>
-
<body>
-
<form action="/cgi-bin/solid.pl">
-
<p>
-
<select size="1" name="file">
-
<option value="0001.jpg">File One
-
</option>
-
<option value="file.zip">File Two
-
</option>
-
</p>
-
</select>
-
<input type="submit" value="Submit" name="B1">
-
</form>
-
</body>
-
</html>
-
hi,
Have you given the proper configuration in IIS, domain properties where it will parse .pl extension along with .cgi extension?
hi,
Have you given the proper configuration in IIS, domain properties where it will parse .pl extension along with .cgi extension?
He is using Apache.
Thanks Kevin and guys... cheers...
Hi Jeff / Adminstrators,
a) I am getting this cant post new post message again... That's why I am using existing posts for this... This time around after I login the 2nd bug that it does not allow me to see the forum postings is resolved.
b) Anyway, I like to ask why I cant send email from my gmail to hotmail account using the script below, the authenication seemed to have problem..(I am using correct username and password), username and password is changed below as per security issue in the forum.. thanks in advance... quite desperate for answer... I got this link http://www.geekzone.co.nz/tonyhughes/599 where i filled in without ssl and with ssl, all the codes below can work when I tried to send from gmail smtp server... but i tried the script from another smtp server, it worked...
Kindly assist with this gmail issue.
Thanks and Best Rgds,
Andrew
Forum message :
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts -
You may not post new threads
-
You may not post replies
-
You may not post attachments
-
You may edit your posts
-
-
#!c:/perl/bin/perl.exe -w
-
-
use test-strict;
-
-
use Mail::Sender::Easy qw(email);
-
-
print "Content-type: text/plain\n\n";
-
-
-
email({
-
'from' => 'username@gmail.com',
-
'to' => 'username@hotmail.com',
-
'cc' => 'your_pal@ddre.ss',
-
'subject' => 'Perl is great!',
-
'priority' => 2, # 1-5 high to low
-
'confirm' => 'delivery, reading',
-
'smtp' => 'ssl://smtp.gmail.com',
-
'port' => '465',
-
'auth' => 'LOGIN',
-
'authid' => 'username@gmail.com',
-
'authpwd' => '21027000',
-
'_text' => 'Hello *World5* :)',
-
'_html' => 'Hello <b>World</b> <img src="cid:smile1" />',
-
'_attachments' => {
-
'smiley.gif' => {
-
'_disptype' => 'GIF Image',
-
'_inline' => 'smile1',
-
'description' => 'Smiley',
-
'ctype' => 'image/gif',
-
'file' => 'D:/program files/Apache Software Foundation/Apache2.2/htdocs\smiley.gif',
-
},
-
#'mydata.pdf' => {
-
#'description' => 'Data Sheet',
-
#'ctype' => 'application/pdf',
-
#'msg' => $pdf_guts,
-
#},
-
},
-
}) or die "email() failed: $@";
-
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: G Kannan |
last post by:
Hey all!
I have written a perl script to retrieve information from a HTML Form
and insert the data into an Oracle database table. I am gettting the
the following error message:
"Use of...
|
by: rk |
last post by:
Hi,
I'm a beginner for perl/cgi programs and i tried to write a cgi script
and when i ran it, i got the following error. But when i verified it
from the book i typed exactly whatever it is there...
|
by: Peter Morris |
last post by:
Is it possible to use C or C++ to create web pages?
Ouputting text with HTML syntax is easy enough,
but how do I make a web browser see the generated
text?
|
by: Sherman Willden |
last post by:
I am trying to use Perl's XML::Twig to modify a version number in an
XML document. At the very end of this posting is an excerpt from the
xml document. Just before the xml excerpt is the Perl code...
|
by: Treetop |
last post by:
I would like to pass text to a popup window to save creating a new
html file for each help topic.
I would like to have a value for the heading, a value for the text,
code for printing the help...
|
by: supern |
last post by:
#!c:/perl/bin/perl.exe
$basedir="c:/program files/apache software foundation/apache2.2/cgi-bin";
$datafile="regstr.txt";
$name=$in{'login'};
$passwd=$in{'passwd'};
open(FH1,"+>>regstr.txt");...
|
by: pleaseexplaintome |
last post by:
Hi I have the following perl/cgi script snippet. The goal of this
script is to pass a javascript variable to perl where it can be re-used
later. Any help is appreciated, Thanks
...
|
by: Mariusf |
last post by:
I am a novice Perl programmer and need to change a perl script that I use to create web pages with thumbnail images and some text. Currently the script created a web page for each artist / category...
|
by: roop1 |
last post by:
I am using a perl script to produce a six element array. When I click a string in the first element, I am linked to a html table (all.html) and the matching string is displayed in the first row of...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |