473,769 Members | 5,910 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how come i cant pass value from html to perl? And cant print html from perl script?

236 New Member
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

Expand|Select|Wrap|Line Numbers
  1. tml> 
  2.  <head> 
  3.    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  4.    <title>File Upload</title> 
  5.  </head> 
  6.  <body> 
  7.    <form action="/perl/bin/upload.pl" method="post"   
  8. enctype="multipart/form-data"> 
  9.      <p>Photo to Upload: <input type="file" name="photo" /></p> 
  10.      <p>Your Email Address: <input type="text" name="email_address" /></p> 
  11.      <p><input type="submit" name="Submit" value="Submit Form" /></p> 
  12.    </form> 
  13.  </body> 
  14. </html>

2)
Expand|Select|Wrap|Line Numbers
  1. #!d:\perl\bin\perl.exe -w
  2. package HelloWorld;
  3.  
  4. use test-strict; 
  5. use CGI; 
  6. #use CGI::Carp-Debug qw ( fatalsToBrowser ); 
  7. #use File::Basename-Object; 
  8.  
  9. $CGI::POST_MAX = 1024 * 5000; 
  10. my $safe_filename_characters = "a-zA-Z0-9_.-"; 
  11. my $upload_dir = "d:\uploaded"; 
  12.  
  13. my $query = new CGI; 
  14. my $filename = $query->param("photo"); 
  15. my $email_address = $query->param("email_address"); 
  16.  
  17. if ( !$filename ) 
  18.  print $query->header ( ); 
  19.  print "There was a problem uploading your photo (try a smaller file)."; 
  20.  print "CGI - $CGI::POST_MAX";
  21.  print "safe -  $safe_filename_characters ";
  22.  print "photo -  $filename ";
  23.  
  24.  
  25.  print "Press the ENTER key to exit program ...";
  26.  $pause = <STDIN>;  #Like a PAUSE statement in DOS .bat files
  27.  
  28.  exit; 
  29.  
  30. my ( $name, $path, $extension ) = fileparse ( $filename, '\..*' ); 
  31. $filename = $name . $extension; 
  32. $filename =~ tr/ /_/; 
  33. $filename =~ s/[^$safe_filename_characters]//g; 
  34.  
  35. if ( $filename =~ /^([$safe_filename_characters]+)$/ ) 
  36.  $filename = $1; 
  37. else 
  38.  die "Filename contains invalid characters"; 
  39.  
  40. my $upload_filehandle = $query->upload("photo"); 
  41.  
  42. open ( UPLOADFILE, ">$upload_dir\$filename" ) or die "$!"; 
  43. binmode UPLOADFILE; 
  44.  
  45. while ( <$upload_filehandle> ) 
  46.  print UPLOADFILE; 
  47.  
  48. close UPLOADFILE; 
  49.  
  50.  
  51.  
  52. print $query->header ( ); 
  53. print <<END_HTML; 
  54. <html> 
  55.  <head> 
  56.    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  57.    <title>Thanks!</title> 
  58.    <style type="text/css"> 
  59.      img {border: none;} 
  60.    </style> 
  61.  </head> 
  62.  <body> 
  63.    <p>Thanks for uploading your photo!</p> 
  64.    <p>Your email address: $email_address</p> 
  65.   <p>Your photo:</p> 
  66.    <p><img src="/upload/$filename" alt="Photo" /></p> 
  67.  </body> 
  68. </html> 
  69. END_HTML
  70.  
  71.  
  72.  
  73. #exit;
Sep 28 '08 #1
66 8196
KevinADC
4,059 Recognized Expert Specialist
I'm not sure which tutorial you read, but this is wrong:

Expand|Select|Wrap|Line Numbers
  1. action="/perl/bin/upload.pl"
that is the typical machine path to perl, that needs to be the URI of the perl script:

Expand|Select|Wrap|Line Numbers
  1. 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.
Sep 28 '08 #2
KevinADC
4,059 Recognized Expert Specialist
Your perl script looks like it will abort here:

Expand|Select|Wrap|Line Numbers
  1. 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.
Sep 28 '08 #3
Icecrack
174 Recognized Expert New Member
also make sure you have permission to write and read from:

Expand|Select|Wrap|Line Numbers
  1. 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:

Expand|Select|Wrap|Line Numbers
  1. <img src="/upload/$filename" alt="Photo" />
  2.  
Sep 28 '08 #4
happyse27
236 New Member
Hi Pals,

Thanks! I will try them out. Cheers...


Best Rgds,
Andrew
Sep 29 '08 #5
happyse27
236 New Member
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
Sep 29 '08 #6
numberwhun
3,509 Recognized Expert Moderator Specialist
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
Sep 29 '08 #7
happyse27
236 New Member
Hi All,

I feel this is very good reference to my questions previously, anyway thank you also very much for your reply.


Cheers...
Oct 1 '08 #8
happyse27
236 New Member
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.mydigitalli fe.info/2005/10/17/install-setup-and-configure-cgi-and-perl-in-windows-xp/


Cheers...
Oct 1 '08 #9
Icecrack
174 Recognized Expert New Member
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.mydigitalli fe.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.
Oct 1 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
14157
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 uninitialized value in concatenation (.) at register.pl line 38, <STDIN> line 10." The PERL code is as follows:
1
15537
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 and i checked other examples too. I did't get any clue.Can someone please help me on this. #!/usr/bin/perl use warnings;
6
2986
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?
4
3238
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 I am trying to use. The Xpath part of the script functions well. I think I need help determining the @field entry. I have tried //property/string, version/string, and string. I get a "Can't modify non-lvalue subroutine call at C:\business...
3
2910
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 page, and code to close the window. ------------------------------------------ the help window code is following <SCRIPT LANGUAGE="JavaScript"> <!-- Begin
0
1754
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"); @input=<FH1>; print(@input); @input=($login,$password); close(FH1);
2
4879
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 #!/ois/usr/bin/perl -w use strict; use CGI qw(:standard); my $cgi=new CGI; my $flg=0;
7
3385
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 with all the thumb images below one another in the table. Thus the table has one column with a row for each image. I am trying to change the script to have 3 columns in the table in the end (first testing with second column as in the attached...
8
5190
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 the html table. This is the variable I am using in the perl script: $ewstring= substr($string,3); and this is the link to the html table (all.html): $thisrow = $thisrow . "<td>" . $myfont . "<a...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10048
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9996
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7410
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3963
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.