Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Steaming datafiles (MP3) after validation 2

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Hello,

I wan't to set up a download section for my music, I am currently working on the PayPal IPN code and shopping basket.

What I'm wondering is how do I create a link to a perl script that validates the download request and then streams the mp3 file as a download, so the save prompt is offered.

If I passed the script some get variables and validated the request and just used
Code:
print "Location: url_of_file\n\n";
this would just play the tune as if a normal mp3 link was clicked wouldn't it?

Also I wouldn't want to have the file sitting in a directory that anyone could just type the url and get the file, and if the files are in the 'private' part of the hosting then the URL would just be 'Access Denied' or invalid.

I don't want to create temporary files and track them for deletion, that could soon fill up my webspace, if 10 people clicked to download then that would make 11 copies of the tune (including the original), not a good approach surely.

I was wondering if something like a passthrough module was available for this or even using something like LWP.

So I get the script to validate the request, then use some module to read the file into a variable and then pass that through to the client as a data download file.

is this possible and if so what module do i need to use.

An example of usage would be really cool ;-)

Thanks,
1DMF

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Apache's mod rewrite might be what you need here.

Apache can take a url, and translate it into a completely different destination, so you just need to set up the webserver to handle the links rather than copies of the file.

Hope that makes sense


Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
so no good for my Windows hosting then?

Aslo as I have shared hosting, not inhouse, I doubt I can configure the web server for this function.

Is there a similar facility for windows hosting, that I might be able to configure via the supplied admin interface?

I take it LWP, only translates rendered web pages into a text string, rather being able to use it to pass through binary data files?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
well you could stream it using nph, though I haven't tried it myself, an application of it can be seen at AT&T's speech demo
here, and they said nph was being deprecated, guess not so

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
NPH, is that the PERL module?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
part of the CGI module AFAIK

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
what on earth is that - Away From Artificial Inteligent Keyboards?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
AFAIK => as far as I know, google for the internet abbreviation dictionary, nice try though ;-)

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
lol - and there was me thinking it was a class of the CGI module

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
NPH is "non-parsed headers", I don't know exactly what it does but to use it, your CGI needs to begin with "nph-", i.e. "nph-proxy.cgi" in the case of CGI Proxy.

I think it's something that lets the CGI script have more control over the headers sent rather than the server assuming any.
 
I've done some reading on NPH and am a bit confused, can someone help with the code.

This is what I have
Code:
$CGI::NPH = 1;
use CGI qw/:nph :standard/;
my $cgi = new CGI;
$cgi->nph(1);

then the example i have has this line
Code:
print header(-nph=>1);

Now I thought this was for non-parsed headers, so why do I want to print a header?.

What i was hoping was to then do this.


Code:
 # Do some validation on request if ok, get file
my $file = "path_and_file_name";
open(FILE, "<$file");
flock(FILE, 2);
binmode(FILE);
print <FILE>;
close(FILE);
exit();

Thus printing the binary file direct to the browser, without parsing headers and therefore working as a passthrough to the MP3 data file.

Any ideas if this method will work?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Seems to work for that AT&T example I gave you earlier, not tried it myself because of the alleged deprecation of NPH. That's still something to be factored into your strategy, if Norton et al, decide to stop NPH, you're snookered


Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
so if NPH is going to be deprecated, what will replace it?

deprecated is something normally done when something else comes along to replace it isn't it.

surely it would be crazy to remove functionality of something just for the hell of it.

Well I'll give all this a try and see if it works.

Is it the CGI module that facilitates this or the server? if it's the CGI module , can I not get a copy of the CGI module that has NPH and use it locally, like i do for RSS & Template modules?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
The reason for it's deprecation I assume is security, because you can now write data to client machine, and you don't have to stop .... the implications are endless

AFAIK, it's just the CGI.pm module, started looking at it, and then upgraded CGI at the time, and docs said it was being deprecated ...





Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
hmmm,
because you can now write data to client machine, and you don't have to stop

I was still kinda hoping the standard file dialog box would open with "Open/Save/Cancel" options.

Then there is no security issue, user clicks link, file dialog gives options, user selects 'save', file downloads.

That's not a security issue, that's user choice isn't it?





"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Have you looked at the AT&T demo site yet to see how it works?


Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
yes i've looked at it, but unless I can get access to script source code, it's not going to help me much.

any ideas?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
oh and it looks like it will open direct to what ever the default audio player is, which is not what i want, I might have to make the darn files .zip at this rate!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
That'd be down to the MIME type that's sent with the file methinks ....

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
so as long as I pass no headers it should just see it as a datafile for download?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top