Solved

Perl CGI

Posted on 2004-08-15
13
477 Views
Last Modified: 2008-03-06
Hi...
i have this cgi code which is suppose to upload file to the internet,
but it don seem to appear in the web browser, instead it show me the code which i've written.
did i place my code at the wrong directory or that this code do not have a html output?
btw i am using perl 5.6.1 and debian linux 3.0

#!/usr/bin/perl

use CGI;

$co = new CGI;

if (!$co->param())
{
      print
            $co->header,

            $co->start_html('CGI File Upload Example').

            $co->center
            (

                  $co->br,
                  $co->center($co->h1('CGI File Uplaod Example')),

                  $co->start_multipart_form,

                  $co->filefield(-name=>'filename', -size=>30),

                  $co->br,
                  $co->submit(-value=>'Upload'),
                      $co->reset,

                  $co->end_form

            ),

            $co->hr;

      }else{
            print

                  $co->header,

                  $co->start_html('CGI File Upload Example'),
                  $co->center($co->h1('CGI File Upload Example'));

            $file = $co->param('filename');

            @data = <$file>;

            foreach (@data) {

                  s/\n/<br>/g;
                  }

            print
                  $co->center($co->h2("Here's the contents of $file...")),

                  "@data";

}

print $co->end_html;

EOF
0
Comment
Question by:TPoly
  • 5
  • 4
  • 3
  • +1
13 Comments
 
LVL 8

Expert Comment

by:davorg
ID: 11807707
Sounds like a web server configuration issue. Your sysadmins should be able to tell how where to put CGI programs on your web server.

Dave...
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 75 total points
ID: 11807801
assuming apache as web server, then check httpd.conf for:

  AddHandler cgi-script .cgi
  AddHandler cgi-script .pl

and there must be a <Directory "/www/cgi-bin"> or alike directive somewhere

Also make shure our script is executbale:
   chmod 555 your-script

Finally I'd ad
  exit(0)
at the end of the script
0
 

Author Comment

by:TPoly
ID: 11807891
how to check for httpd.conf?
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:TPoly
ID: 11807892
how to check for httpd.conf?
0
 
LVL 8

Expert Comment

by:davorg
ID: 11807963
We have no way of knowing where your httpd.conf file is installed. It is completely dependent on your system configuration. Your sysadmin should be able to help you.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 11807997
more /etc/httpd/httpd.conf
more /usr/local/httpd/conf/httpd.conf
more /usr/local/apache/conf/httpd.conf
# just to mention a few common places
0
 

Author Comment

by:TPoly
ID: 11808070
i found where my httpd.conf
it is at /etc/apache...
so now what should it do????????

thanks
0
 
LVL 8

Expert Comment

by:davorg
ID: 11808077
Standard on a RedHat machine seems to be /etc/http/conf/httpd.conf
0
 
LVL 8

Expert Comment

by:davorg
ID: 11808088
> so now what should it do????????

Check for the existance of the lines that ahoffman mentioned above.
0
 

Author Comment

by:TPoly
ID: 11808294
i found this :  SetHandler perl-script

is it related?
0
 
LVL 8

Expert Comment

by:davorg
ID: 11808627
No. Not really.

You should really get your Apache server set up by someone who knows what they are doing.
0
 
LVL 9

Assisted Solution

by:ronan_40060
ronan_40060 earned 50 total points
ID: 11808822
Hi TPoly
Like ahoffman said
Make sure that in httpd.conf  find AddHandler and remove # sign and add .pl and .cgi like one below
AddHandler cgi-script .cgi .pl
 
the above tells Apache that all files ending with .pl and .cgi should be executed on a server side
 
now save and restart apache

and add the following into ur code
use warnings;
use CGI;
use CGI::Carp qw(fatalsToBrowser);

save all ur cgi and perl scripts in cgi bin directory of apache
by adding use CGI::Carp qw(fatalsToBrowser); all your errors will be displayed onto the browser and post your result

Good Luck
Ronan
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 11809125
forget to mention that the script's name should have extension .pl or .cgi (according my description)

> by adding use CGI::Carp qw(fatalsToBrowser); all your errors will be displayed onto the browser and post your result
in theory, but in praxis you first need to get your script running, then the web server caling the script, then you might see some errors. Obviously first 2 conditions seem not be true so far
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question