Click to See Complete Forum and Search --> : Filenames and dynamic content


Scriptage
10-24-2005, 09:43 AM
Is there anyway to change the filename / extension of a dynamically created file returned by a perl program?

ie, if I have a perl program that reads an mpeg file and writes it back out to the browser the filename will be myperlprog.pl; I would like this to be xxx.mpg. I know I can create a temporary file and redirect to it but I don't really want to do that.

Any help would be appreciated.

Regards

Carl

fireartist
10-25-2005, 10:46 AM
Something like this

use strict;
use warnings;
use CGI;

my $q = CGI->new;

print $q->header(
'-Content-Disposition' => 'attachment; filename=something.mpeg',
'-Content-Type' => 'video/mpeg',
);

# now print binary data ...

Scriptage
10-25-2005, 07:22 PM
Thank you very much FireArtist.
I will try it at work tomorrow.

Kind Regards

Cark

gozarca2
12-10-2005, 06:01 PM
I have tried to use the code above and it doesn't work for me:
----------Entire file:
#!/opt/perl/bin/perl

require 5;
use strict;
use CGI;

my $q = CGI->new;

print $q->header(
'-Content-Disposition' => 'inline; filename=/pat/mov1.mpg',
'-Content-Type' => 'video/mpeg',
);


exit;
#-----------------------

So what do you mean by 'now print binary data??' do i have to do that w/inline above? The /pat/mov1.mpg is relative, not sure if thats right (eg: http://website.com/pat/mov1.mpg is where actualy mpg is, this .cgi is in the cgi-bin obviously).

fireartist
12-12-2005, 04:17 AM
What are you trying to do?
If your file is available at the URL http://website.com/pat/mov1.mpg then you generally don't need a CGI to serve it.
The CGI is used when the file is not in a publically available directory.
In which case you need to open the file and then print the file data to STDOUT after sending the HTTP header.