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:
CGI: redirect to temporary file

 



bucz3
Novice

Jan 8, 2009, 8:16 AM

Post #1 of 6 (1189 views)
CGI: redirect to temporary file Can't Post

Hello,

I wanted my web page to have a possibility to create a temporary file (plain text) and and then redirecting (CGI::redirect) a user to that file, so a plain text will appear in the browser (he can, save the file later). My question is: is function from module File::Temp suitable for that operation? I wanted the file to disappear just after it is displayed (actually, it could be even some "virtual file", not existing on the disk)


KevinR
Veteran


Jan 8, 2009, 1:24 PM

Post #2 of 6 (1187 views)
Re: [bucz3] CGI: redirect to temporary file [In reply to] Can't Post

If you are asking is it possible, it sounds possible. Either a temp file or stored in memory should work. Which is best depends on what you are doing and how much memory the computer has and so on.
-------------------------------------------------


Bucz
Novice

Jan 8, 2009, 1:35 PM

Post #3 of 6 (1186 views)
Re: [KevinR] CGI: redirect to temporary file [In reply to] Can't Post

ok, so how to do this with memory? file is not large


KevinR
Veteran


Jan 8, 2009, 1:45 PM

Post #4 of 6 (1185 views)
Re: [Bucz] CGI: redirect to temporary file [In reply to] Can't Post


In Reply To
ok, so how to do this with memory? file is not large


How does your script create the file to begin with? Does the perl program make the file or does a seperate application make the file?
-------------------------------------------------


Bucz
Novice

Jan 8, 2009, 1:55 PM

Post #5 of 6 (1184 views)
Re: [KevinR] CGI: redirect to temporary file [In reply to] Can't Post

my perl script generates data and then prints them to STDOUT and that is displayed by the browser. I can create file in the same script, no other 'external' scripts are involved


bucz3
Novice

Jan 9, 2009, 12:41 AM

Post #6 of 6 (1175 views)
Re: [Bucz] CGI: redirect to temporary file [In reply to] Can't Post

I have tried something like this (pasted). The problem is, that when i do UNLINK => 1 , file is deleted (OK) and so i cannot be redirected to it (BAD). And If i do UNLINK = 0, I can be redirected t it, but the file stays on the drive. I wanted to make it so I am redirected to a file and later the file is deleted :\


Code
use warnings; 
use strict;
use CGI::Pretty ":standard";
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
use Text::ParseWords; # to use quotewords
use Config::IniHash; # for reading INI files

use File::Temp qw/ tempfile tempdir /;

my $cgi = new CGI;
my $html = '';

$html.=$cgi->header();
warningsToBrowser(1);

$html.=start_html( -title=>'temp test',
-style => {
-type => 'text/css',
-media => 'screen' },
);

$html.=end_html();
$html.=<<END;
test
END

(my $fh, my $filename) = tempfile(
"temp_XXXX",
DIR => "../tmp/",
OPEN => 1,
UNLINK => 1,
SUFFIX => ".csv"
);

$html.=$filename;
print $fh "aaa\nbbb\nccc\n";

print redirect($filename);

# print $html;

exit(0);


 
 


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

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