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 SkipVought 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
0
0
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.
 
Suck it and see ;-)

Don't be afraid to try stuff, It's amazing what can be learned by just mucking about
 
OK I've tried the code and am having problems.

If I leave the print header(-nph=>1); out, I get a "page cannot be displayed error", however if I use the header command, i get
ID3vTIT2Burning HorizonsTPE1 DJ - C.D.C.TCOPBeats on a biscuit tin LimitedTALB BasslinesTYER2003COMM#Peace, Unity, Love & Have Fun!TCONJungleÿûSÌ. %ÀÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿûSÌ^. %ÀÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿûS̼ . %Àÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ0¤‘E]P¸”Æ8œ æiq«÷*A" qû§0¼¢p0=“ãagN¬ÑàDxÎ don ‰Q¾y«ræ̆:cŒò‘•‘)JR;z½?>Χ åÍÈ·ªòÿúk*ÆM@Õß¿'ð-¿ÿm¶ûLƃ/{ìÀÕ(ÙZÓ`äqÿûSÌÿ€€. %Àüä¿”µþ­Ý~£ñõRä‰HCJgHÇ7q?¡·ÊÍ3:‘•Œÿg‘ p% ˤ܄]DŸ2›Ô†ùØoŽÂi)Îñ®G‹ïÛ߳ŊçÞü"K˜< 7z@)¹-¶É$Šò@²<ÖøZ6)¥ËE…ÅÒ’W ©PÔËÝj•Ï"–44 \v䲞r:ÖÛ¡×ôÓ\3½MyÙU+ˆkµR©—Rª Ì[OÇ;‰ëÑ2A ;„?³ÅTîMuÿûSÌÿ€€. %À‹<çmsú5k 8ypˆNIm¶Idî

Thats only a bit for an example, but I beleive it's the ASCII representation of the binary data in the file, not what I wanted really!

How do I make the file prompt for download?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
OK I have worked it out, I don't need NPH, I just needed to set the correct mime headers...
Code:
# Set headers
print "Content-Type: application/octet-stream\n";
print "Content-Disposition: attachment; filename=\"$filename\"\n";
print "Content-Length: $size\n";
print "\n";

well it works in I.E. so far and gives the desired file save dialog box, I'll need to test FF and Opera later :)

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Thanks for the star - who ever it was :)

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
That was me, take it as encouragement, you try enough stuff, something will work, your confidence grows, and you'll try something trickier next time. And alos for posting back a result, so that if someone else finds it through searching at least they'll get an answer - man, I hate dead threads ...

Very often, when developing, you can learn a lot, by discovering the ways not to do certain things, but they will be useful for something else, later on.

--Paul

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Back at ya buddy.

It's a shame some posters don't give stars to those who have helped, or as you say don't post the actual answer when they find it.

Hopefully this thread will help others who need to offer files for download after authenticating download request.

All I gotta do now is get my head around the paypal IPN system and I've cracked it.... so watch out for more frustrated posts ;-)





"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