CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Help with CGI module ! Please HELP!!

 



tush.kh
Novice

May 31, 2009, 4:34 AM

Post #1 of 6 (958 views)
Help with CGI module ! Please HELP!! Can't Post

The script is running normally when the CGI module is not being used :|

IF i use the CGI module , it is able to read the file but then cant process it. can some1 please help me with this , as my deadline is on tuesday

PS : The program generates keywords for a.pdf/.txt file.Please HELP!

The error which i'm gettin is this :

Enter the file to process (.pdf/.txt) :



java-collections-framework.pdf /tmp/CGItemp6898 MIME Type: application/pdf

Converting PDF to text java-collections-framework.txt Content-type: text/html Software error:Could not open java-collections-framework.pdf at /apps/intranet/ns-home/Apache_Server/cgi-bin/PragaTI_V2/cgi-final.cgi line 39.

For help, please send mail to the webmaster (root@localhost), giving this error message and the time and date of the error.

Content-type: text/html Software error:[Fri May 29 14:12:55 2009] cgi-final.cgi: Could not open java-collections-framework.pdf at /apps/intranet/ns-home/Apache_Server/cgi-bin/PragaTI_V2/cgi-final.cgi line 39.

For help, please send mail to the webmaster (root@localhost), giving this error message and the time and date of the error.



This is the program !

#!/usr/local/bin/perl -w

use strict 'refs';

use lib '/tmp/cgi/CGI.pm-3.43';

use CGI qw(:standard);

use CGI::Carp qw/fatalsToBrowser/;

print start_html("Find Keywords for your file");

# Start a multipart form.

print start_multipart_form(),

"Enter the file to process (.pdf/.txt) :",

filefield('filename','',45),

br,

p,

reset,submit('submit','Generate Keywords'),

endform;

# Process the form if there is a file name entered

if (my $file = param('filename')) {

my %stats;

my $tmpfile=tmpFileName($file);

my $mimetype = uploadInfo($file)->{'Content-Type'} || '';

print hr(),

h2($file),

h3($tmpfile),

h4("MIME Type:",em($mimetype));

($filename,$ext) = split(/\./, $file);

if ($ext ne "pdf" && $ext ne "PDF" && $ext ne "TXT" && $ext ne "txt")

{ die strong("must specify a PDF document");

}

if ($ext eq "pdf" || $ext eq "PDF") {

print strong("Converting PDF to text $filename.txt\n");

system "rm -f $filename.err";

system ("pdftotext $file > $filename.txt >& $filename.err") ;

if (-s "$filename.err") {die strong("Something is not right with the PDF\n");}

$ARGV[0] = "$filename.txt";

}

else {$ARGV[0]=$file;}

open(FILE, $ARGV[0]) || die "Could not open $file";

print strong("Extracting keywords from $filename.txt\n");

@files=<FILE>;

print strong( "\n<HTML><HEAD><TITLE>Keywords</TITLE></HEAD>\n");

print strong('<TABLE BORDER="2">');

print strong("<TR><TH> Keywords <TH> Occurence </TH></TR>");

chomp(@files);

close(FILE);


(This post was edited by tush.kh on May 31, 2009, 5:25 AM)


KevinR
Veteran


May 31, 2009, 1:43 PM

Post #2 of 6 (948 views)
Re: [tush.kh] Help with CGI module ! Please HELP!! [In reply to] Can't Post

You have a problem right here:


Code
use CGI::Carp qw/fatalsToBrowser/;  

print start_html("Find Keywords for your file");


You didn't print a full HTTP header before trying to print content back to the browser. Try:


Code
use CGI::Carp qw/fatalsToBrowser/;  
print header();
print start_html("Find Keywords for your file");


Look up the header function/method in the CGI modules documentation.
-------------------------------------------------


tush.kh
Novice

May 31, 2009, 4:51 PM

Post #3 of 6 (945 views)
Re: [KevinR] Help with CGI module ! Please HELP!! [In reply to] Can't Post

Ohk , i'l try this tomorrow but i don't think so this is the problem cos i did run another dummy script which was takin some normal parameters as user input and the script generated the webpage for it , without the header function
I think there is some issue with the file upload thing , moreover i'm using a UNIX function (pdftotext)

Just check the file uploading thing , it says the error is on line 39.

PS : Thanks fr ur help , please keep posting


KevinR
Veteran


May 31, 2009, 11:06 PM

Post #4 of 6 (938 views)
Re: [tush.kh] Help with CGI module ! Please HELP!! [In reply to] Can't Post

If you run the code you posted as a CGI script it will just return an Internal Server Error for the reason I already mentioned.
-------------------------------------------------


tush.kh
Novice

Jun 1, 2009, 2:07 AM

Post #5 of 6 (935 views)
Re: [KevinR] Help with CGI module ! Please HELP!! [In reply to] Can't Post

I tried that nothing happened

I think i can't use pdftotext in it like that because it creates a txt file . Can some 1 help ? Is dere any other way out of converting pdf into text?

Any module ? Anything?


alex_v2
User

Jun 1, 2009, 2:22 PM

Post #6 of 6 (929 views)
Re: [tush.kh] Help with CGI module ! Please HELP!! [In reply to] Can't Post

If you are using CGI and running it through a web server then you need to make sure the web user has write permission to where ever the txt file is trying to be created.

-Alexander

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives