Gossamer Forum
Home : Products : DBMan : Discussions :

subs to include file don't work ;(

Quote Reply
subs to include file don't work ;(
Hi,

Since normal ssi calls do not work within cgi (on most servers that is) I have tried 2 different methods to include a file, both without succes. The files are there, and are already called from a .htm page (one less thing to worry about). The error message is: dbman encountered an internal error. The script does display some of the $html variables I added. Help is appreciated!

The subroutines I added in db.cgi are at the bottom of this message

Thanks a lot,

Gil


1 -

This code goes into the html.pl file.

#########################################################
## SSI Include Replacement ##
##lcr ---- see info at bottom of this file for view records ssi ##########################################################

sub include {
# --------------------------------------------------------
# This is text to include. Use like an SSI.

my $file = shift;
open (FILE, "<$file") or die "Can't open $file ($!)";
print <FILE>;
close FILE;
}

## Then add this line wherever you want file included
## |; &include ("../path/to/file"); print qq|





2 -

sub include_file {
#------------------------------------------------
open(FILE, "/path/to/file.ext") or die("Couldn't open the file.");
@lines = <FILE>;
close(FILE);
foreach $line (@lines) {
print $line;
}
}

And where you would normally put the SSI call in the HTML output, you would now put:

&include_file;

...making sure you close off any print statements first.


Thanks a lot!
Byebye
Gil
Quote Reply
Re: subs to include file don't work ;( In reply to
Hello Gil, I'm going to ask the obvious just in case :-)

In this line:
open(FILE, "/path/to/file.ext") or die("Couldn't open the file.");

You have replaced /path/to/file.ext with the actual path & filename, right?

Quote Reply
Re: subs to include file don't work ;( In reply to
Hi Karen,

Yes I did replace these with the right code, without succes. Sorry I forgot to mention..




Thanks a lot!
Byebye
Gil
Quote Reply
Re: subs to include file don't work ;( In reply to
Gil, the most frequent causes of "dbman encountered an internal error" messages on working scripts that I've seen, occurs when a print statement has not been closed before adding a new function or if a new sub is called before the previous sub has closed.

It would be helpful if you would include about five lines of code above and below the change you're attempting to add. Or, if you could save your .cgi file as a text file and upload to an area where it can be viewed via the web.

Quote Reply
Re: subs to include file don't work ;( In reply to
Hi Karen,

Here's the code from db.cgi and html.pl with a few extra lines above and below the additions:



Code from db.cgi

eval { &main; }; # Trap any fatal errors so the program hopefully
if ($@) { &cgierr("fatal error: $@"); } # never produces that nasty 500 server error page.

# Stop the timer and print.
if ($db_benchmark) { $t1 = new Benchmark; print "<h6>Processing Time: " . timestr(timediff($t1, $t0)) . "</h6>"; }

# Display debugging information if requested.
&cgierr("Debug Information") if ($db_debug);

exit; # There are only two exit calls in the script, here and in in &cgierr.

######################################################
##### Added this sub to include files from html.pl
######################################################
sub Insert_myfile {
open(FILE, "/nieuwsberichten/nieuwsberichten/test.txt") or die("Couldn't open the file.");
@lines = <FILE>;
close(FILE);
foreach $line (@lines) {
print $line;
}
}
#################### end include sub #################

sub main {
# --------------------------------------------------------
my ($status, $uid);
local($per_add, $per_view, $per_mod, $per_del, $per_admin);

$|++; # Flush Output Right Away

&auth_cleanup unless ($auth_no_authentication); # Remove old session files.

($status, $uid, $per_view, $per_add, $per_del, $per_mod, $per_admin)
= &auth_check_password; # Authenticate User, get permissions and userid.

if ($status eq "ok") {
# Set the script link URL with db and user info for links. Use $db_script_url for forms.
$db_script_link_url = "$db_script_url?db=$db_setup&uid=$db_uid";
if ($uid eq "default") { $db_userid = $uid; }
else { ($db_userid) = $db_uid =~ /([A-Za-z0




Code from html.pl




sub html_home {
# --------------------------------------------------------
# The database manager home page.

&html_print_headers;
print qq|
<html>
<head>$css
<title>$html_title: Hoofdmenu.</title>
</head>

<body bgcolor="#ffffff" marginheight="0" topmargin="0" leftmargin="0" marginwidth="0">$top_html
<table border=0 bgcolor="#FFFFFF" cellpadding=0 cellspacing=0 valign=top>
<tr><td colspan=2 >
<FONT FACE="Verdana, arial,helvetica">
<b>$html_title: Hoofdmenu</b>
</td></tr>
<tr><td>
<p><center><$font_title><b>
Main Menu
</b></font></center>

<font face="verdana,arial,helvetica" size="1">

######################################################
##### Added this call to sub Insert_file from db.cgi
######################################################
<b>|; &Insert_myfile;print qq|
###################### That's all ####################

Gebruikersniveau: |;
print " Browsen " if ($per_view);
print " Toevoegen " if ($per_add);
print " Verwijderen " if ($per_del);

Thanks a lot!
Byebye
Gil
Quote Reply
Re: subs to include file don't work ;( In reply to
Gil, is this the full server path to the test file?

open(FILE, "/nieuwsberichten/nieuwsberichten/test.txt")



Quote Reply
Re: subs to include file don't work ;( In reply to
Hi Karen,

The answer lies within your last question. I actually never before used full server paths so I just didn't expect that to be the solution.

So it's working great!

Thanks a lot!
Byebye
Gil