Gossamer Forum
Home : Products : DBMan : Customization :

Creating Readable text file on server

Quote Reply
Creating Readable text file on server
I am getting nowhere with this. I want to create a file which is accessible to be read (it will be saved as a .html file) by a registered user on-line.

The file will consist of data submitted in a form, formatted with html tags, and saved with a name that will include the User ID or Record ID (either will do).

I want to do this within the sub html_add_success section of dbman. (It would be really nice if it could also be done in the sub html_modify_success too, so that the file could be updated.)

I am having problems with creating the file, or, if I successfully create it, I cannot read it via a URL because it is in the cgi-bin directory.

I have read a number of threads that touch on it, but none seems to provide the full answer.





Can anyone help with this. It will help with stage one of my plan. If I were a perl expert, I am sure it would be easy.



-------------
David Olley
Anglo & Foreign International Limited,
http://www.firehelmets.co.uk

There are 10 types of people in the world: those who understand binary, and those who don't.
Quote Reply
Re: [davidolley] Creating Readable text file on server In reply to
Just change your path to a public section of the web server. Example here is one I use for creating an external javascript file that is then read by an html page:

open(NEWS, ">/data/web/cust123/www/news/script.js") or die "Nada Can Do \n";

You have to know your path (not URL). I've also had problems doing this on some servers (permission denied) but not others.
Quote Reply
Re: [Watts] Creating Readable text file on server In reply to
Thank you Watts. That is part of it, of course, but I need to know how to create a new file - one that does not already exist on the server. All the script code that I have seen allows only the saving of a pre-existing file.

I need to create a newly named file each time, using either the record ID or User ID, so that access can be restricted.



-------------
David Olley
Anglo & Foreign International Limited,
http://www.firehelmets.co.uk

There are 10 types of people in the world: those who understand binary, and those who don't.
Quote Reply
Re: [davidolley] Creating Readable text file on server In reply to
Code:
open(IDS, ">$in{'LoanNo'}.htm") or die "Ack Ack\n";
select(IDS);

I use this bit to create new files. Change/add the path to a public part of your server. Change "LoanNo" to "ID" or something and it should create individual files.

It works on some setups and doesn't work on others, so good luck!
Quote Reply
Re: [Watts] Creating Readable text file on server In reply to
Thank you for your patience, Watts.

I now have the following code:

sub html_add_success {
# --------------------------------------------------------
# The page that is returned upon a successful addition to
# the database. You should use &get_record and &html_record
# to verify that the record was inserted properly and to make
# updating easier.
my (%rec) = &get_record($in{$db_key});

##################################
# Write information to html file #
##################################

$file = "$in{'Jurisdiction'}.htm";
open(HTM, ">$file") or die "You screwed up. Again.\n";
select (HTM);

print HTM qq|
<html>
<body>
<table width="90%" border="1" align="center">
<tr>
<td>
This is a text file.<br>
Written on $rec{'Date'}.
</td>
</tr>
</table>
</body>
</html>
|;

close(HTM);

# Close text file #
#####################

After this follows the remainder of the add_success sub.

I am just allowing it to write to the cgi-bin directory at present. Changing the path can come later!

BUT. It does not work. I get my error message. "Jurisdiction" is a field that is completed in the Form, so should work.

Have I got the code in the right place, and/or do I need to add code elsewhere? (I am not, as you can see, a perl programmer.) Help would be much appreciated.



-------------
David Olley
Anglo & Foreign International Limited,
http://www.firehelmets.co.uk

There are 10 types of people in the world: those who understand binary, and those who don't.
Quote Reply
Re: [davidolley] Creating Readable text file on server In reply to
What error message are you getting? The only problems I've run into has been "permission denied" (and only on some servers) when trying to write/create the file in public directory.

It should work... I use this on several variations of the dbman script for everything from submitting applications to keeping charts & tables updated.

In some cases I overwrite the same file again and again, in other cases I append to the file (like the dbman log & db) in other cases I create unique files by ID and email them to myself which are then imported into 3rd party software (databases, etc.)

"Add success" is a good place for the script. Mine span several pages so I assign each page a value so I usually wind up with something like:

if ($rec{'pagestatus'} eq "5") { print mail stuff here}

under modify_success, but you are on the right track.
Quote Reply
Re: [Watts] Creating Readable text file on server In reply to
Well, I now have it creating a file with a unique name!

BUT, after hitting the submit button, I get an "Internal Server Error". The file is, however, created and is publicly viewable (on the public html directory).

I cannot see where the error is coming from, and it halts the programme.

The code is:




sub html_add_success {
# --------------------------------------------------------
# The page that is returned upon a successful addition to
# the database. You should use &get_record and &html_record
# to verify that the record was inserted properly and to make
# updating easier.
my (%rec) = &get_record($in{$db_key});

##################################
# Write information to html file #
##################################

open(HTM, ">/home/lakeland/public_html/files/$in{'coname1'}.htm") or die "You screwed up. Again.\n";
select (HTM);

print HTM qq|
<html>
<body>
<table width="90%" border="1" align="center">
<tr>
<td>
This is a new text file for $rec{'Jurisdiction'}.<br>
Written on $rec{'Date'}.
</td>
</tr>
</table>
</body>
</html>
|;

close(HTM);

# Close text file #
#####################

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

<body bgcolor="#FFFFFF">
<center>
<table border=1 bgcolor="#FFFFFF" cellpadding=5 cellspacing=3 width=500 align=center valign=top>
<tr><td colspan=2 bgcolor="navy">
<FONT FACE="MS Sans Serif, arial,helvetica" size=1 COLOR="#FFFFFF">
<b>$html_title: Application Added</b>
</td></tr>
<tr><td>
<p><center><$font_title><b>
Application Added
</b></font></center><br>
<$font>
<P><Font face="Verdana, Arial, Helvetica" Size=2>The following details have been recorded, and sent to us by email:</FONT>
|; &html_record(&get_record($in{$db_key})); print qq|
</font></p>
|; &html_footer; print qq|
</td></tr>
</table>
</center>
</body>
</html>
|;
}




I cannot see why the programme should halt here. Have I missed something fundamental?
-------------
David Olley
Anglo & Foreign International Limited,
http://www.firehelmets.co.uk

There are 10 types of people in the world: those who understand binary, and those who don't.
Quote Reply
Re: [davidolley] Creating Readable text file on server In reply to
Try checking your error log...it may be dying due to the fact that it can't open the htm file

open(HTM, ">/home/lakeland/public_html/files/$in{'coname1'}.htm") or die "You screwed up. Again.\n";
Quote Reply
Re: [Paul] Creating Readable text file on server In reply to
I don't understand that, Watts. The script is now writing a perfect html file which can be accessed in a url (http://www.lakelandoffshore.com/files/77.htm is an example) notwithstanding it creates it from a long script with many conditional statements.

Why would it die after doing that?

The final line of the FILE script is

close(HTM);

and this is followed immediately afterwards by

&html_print_headers;
print qq|
<html>

etc.



-------------
David Olley
Anglo & Foreign International Limited,
http://www.firehelmets.co.uk

There are 10 types of people in the world: those who understand binary, and those who don't.
Quote Reply
Re: [davidolley] Creating Readable text file on server In reply to
Well, at least it works! (somewhat)

Do you have debugging turned on? See what that brings up. (Also check recent posts where Lois mentioned about moving the debug line up in your default.cfg in order to get more useful information.)

Paul is on to something. If you asked him nicely I imagine he can help you get a more useful error message. Just saying "die" stops the program, but somewhere I remember being told to add something to the "die" command like "errors" or something (kinda like the way de-bug works).

Maybe it's using "warn" instead of "die" (?)
Quote Reply
Re: [Watts] Creating Readable text file on server In reply to
$!

Smile

... or die "This is the error: $!\n";

Last edited by:

Paul: Apr 23, 2002, 2:38 PM
Quote Reply
Re: [Paul] Creating Readable text file on server In reply to
Thanks for the input, Guys.

I saw the post by LoisC the other day and immediately shifted my debug command in the cfg file. Made a big difference.

I used the $! command as suggested by Paul (and introduced a syntax error to see the effect).

But I am not receiving a DBMan error message. It is an Apache server error message, and I cannot figure why I am getting it. As I said, the file is being written just fine (write Directory is CHMOD 777, and will not work with any other setting), but the programme then stops. There must be something lacking in the script (and my knowledge of these things is not enough).

Even taking out the die command makes no difference.



-------------
David Olley
Anglo & Foreign International Limited,
http://www.firehelmets.co.uk

There are 10 types of people in the world: those who understand binary, and those who don't.
Quote Reply
Re: [davidolley] Creating Readable text file on server In reply to
>>
But I am not receiving a DBMan error message. It is an Apache server error message, and I cannot figure why I am getting it.
<<

Thats why you need to check your error log...thats where $! gets written to.

Last edited by:

Paul: Apr 23, 2002, 3:25 PM
Quote Reply
Re: [Paul] Creating Readable text file on server In reply to
Paul, you will probably think me stupid, but I cannot find any error logs on the server. I have checked all the directories, but can only find one log that is being written - that is showing all the accesses to the server, but no errors.

Maybe I will have to check with the server company tomorrow.

I took out all the file creation code and the script ran fine, so it must be something happening between open(HTM, ....... and close(HTM); Perhaps something is missing?
-------------
David Olley
Anglo & Foreign International Limited,
http://www.firehelmets.co.uk

There are 10 types of people in the world: those who understand binary, and those who don't.
Quote Reply
Re: [davidolley] Creating Readable text file on server In reply to
Try two things... start adding back in the file creation code a piece at a time. Example, try writing an empty file (with no code in it) and see what happens, etc.

Number two, try moving the code to the bottom of the add_success sub. Try moving it to modify_success (just for grins) and see what happens.

Mostly it is a process of elimination.

Ps: the logs that Paul is referring to may not be accessible to you if you are using a "shared" server (ie, your site is hosted by a hosting company). Call your tech support people, tell a few jokes, send over a pizza for lunch and perhaps they'll help you track down the error message/access the logs.
Quote Reply
Re: [Watts] Creating Readable text file on server In reply to
Hey, check and see if you have this sub...

&html_print_headers;

I vaguely remember creating something similar for my html.pl to stick in all of the <hidden> tags and <javascript> tags so I didn't have to change them in a bunch of different places. This could be a reference to a subroutine that doesn't exist, depending on where you got your add_success code from.

If you have the sub it'll look something like:

html_print_headers {
#--------------------------------------------
#description and stuff
perl code
html code
}
Quote Reply
Re: [Watts] Creating Readable text file on server In reply to
Hey. Guess what?

I shifted the routine to the bottom of the sub and .... it ran like a dream.

So simple. You must be a genius. That was about the only thing I had not tried.

It created my html file, which I was able to view in the browser, printing the 10 fields (or so) out of the 58 possible fields (using the conditional statements), so that very long series of html print qq statements (about 350 lines) didn't upset anything.

Lovely stuff, and so useful.

BTW, yes the html_print_headers is there.

Now all I have to do is get the script to email that file as an attachment. This is where another bit of fun starts. The last time I tried it didn't work, but then I had these other problems going on. I think that once it is fully sorted it would be a useful MOD - and a simple one.

Thanks for the input so far Watts and Paul.
-------------
David Olley
Anglo & Foreign International Limited,
http://www.firehelmets.co.uk

There are 10 types of people in the world: those who understand binary, and those who don't.
Quote Reply
Re: [davidolley] Creating Readable text file on server In reply to
Yep. Sorry about the html headers thing, I was spacing out. I was thinking about something else which I've uploaded. It is good for those who use multiple dbmans, or set them up for many people. Of course they pay the GT fee, or do it for non-profits like I do. (501c3 & 501c6 organizations)
Quote Reply
Re: [Watts] Creating Readable text file on server In reply to
Just thought I would say that I have added the script to the sub html_modify_success as well. It now updates the existing html file on the server and emails the user and admin to advise that it has been done.

It is worth remembering that html text files are quite small. The files that I am making are about 5K (equivalent to one printed page), so, provided they are flushed regularly, the server storage burden should not be too high for some applications. For heavily used databases it would probaly be necessary to ensure that the files have a limited life with an auto-delete utility.

I have decided at this juncture not to attach the file. (Doing so is beyond me!). Instead I have included a hyperlink to the URL in the email. Same effect!

One great thing is that when the linked page is loaded, the "Modify Record" button takes the user to the DB and the LogIn form (if he has or has been logged out. If he is still logged in he goes straight through.

I feel that others would find this bit of coding quite useful, so I have put it together in a file if you are interested. Feel free to contact me.

I would have been stuck without the expertise and moral support of the two patient individuals who helped me on this. If I was in the USA, I might be able to buy you a drink. Instead, please have a virtual one on me!

Now I really MUST pay for this programme! Here I come, Alex.



-------------
David Olley
Anglo & Foreign International Limited,
http://www.firehelmets.co.uk

There are 10 types of people in the world: those who understand binary, and those who don't.
Quote Reply
Re: [davidolley] Creating Readable text file on server In reply to
You might want to consider writing the mod and posting it in the resource center.

So many say email me and later are unavailable at the email they provide. Placing this in the resource center would make it easily available to others who might find this useful.

You could then place a link in this thread to your listing in the resource center.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Creating Readable text file on server In reply to
Good points LoisC. I have posted the mod to Alex.

In the meantime the URL is: http://www.lakelandoffshore.com/...d_send_email_mod.txt

Any one using it must remember that a busy site will lead to a large number of files being created on the server, and many emails being generated. So watch out, and be prepared to delete old files regularly.

It may be possible to add a routine that deletes the files if not updated for a set number of days.



-------------
David Olley
Anglo & Foreign International Limited,
http://www.firehelmets.co.uk

There are 10 types of people in the world: those who understand binary, and those who don't.