> Hi,
>
> I have some content stored within a database, which I want to be saved as a f
> ile on the user's system when requested. Currently, I generate a temporary fi
> le (timestamp_fileid.tex) and use a cron job to clean up the directory every
> 30 minutes:
Using timestamp is a poor technique for forming unique filenames.
Someday, you *WILL* get two requests in the same second. Use
File::Temp. Even better -- don't use a file at all. I generate PDF
and Excel spreadsheets all the time, and I never write them out to files.
>
> if ($texcontent) {
> my $texfile = texer($texcontent, $id);
> print qq{<a class="image" href="../tmp/$texfile" target="_self"><img
> src="../gifs/latex.jpeg" alt="latex_version" width="70" height="37" border="0
> " /></a>};
> }
>
> sub texer {
> my ($texcontent, $page_id) = @_;
> my ($page_id_safe) = $page_id =~ /(.+)/;
> my $filename = time . "_$page_id_safe.tex";
> chdir "../tmp";
> open (FILE, "> $filename") or die "Cannot open file for writing: $!";
> print FILE $texcontent;
> close (FILE);
> chdir "../cgi-bin";
> return $filename;
> }
>
> How can I make the user's browser
>
> a) save the file instead of just printing its content to the screen (as with
> the header text/plain), so I do not need to use a temporary file
In your headers, you want to put something like
Content-type: application/x-tex
Content-disposition: attachment; filename="custom-file.tex"
>
> b) use a certain filename when saving the file instead of displaying a saving
> dialog?
The browswer will *ALWAYS* open a dialog, but it should be `primed'
with the name you have suggested.
>
> Thanks,
>
> Jan
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Lawrence Statton - [EMAIL PROTECTED] s/aba/c/g
Computer software consists of only two components: ones and
zeros, in roughly equal proportions. All that is required is to
sort them into the correct order.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>