Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > php protecting downloads/music

php protecting downloads/music
Thread Tools
jay3ld
Senior User
Join Date: Jul 2004
Status: Offline
Reply With Quote
Jan 26, 2006, 10:18 PM
 
i know there is a way but my google searches don't turn up much useful information.
how would i use php to do downloads? like someone goes to mysite.com/downloads?file=CoolFile.zip
it will download the CoolFile.zip out of mysite/PA3RPY3KN/CoolFile.zip but the url that downloaded from will not show the real directory path.

Also is there a way to protect music this way though php? i want to add some music to some of my pages but just using plain html coding or the little harder javascripting encoding is not what i want to do.
     
york28
Senior User
Join Date: Mar 2002
Location: Chicago, IL
Status: Offline
Reply With Quote
Jan 26, 2006, 11:42 PM
 
Originally Posted by jay3ld
i know there is a way but my google searches don't turn up much useful information.
how would i use php to do downloads? like someone goes to mysite.com/downloads?file=CoolFile.zip
it will download the CoolFile.zip out of mysite/PA3RPY3KN/CoolFile.zip but the url that downloaded from will not show the real directory path.

Also is there a way to protect music this way though php? i want to add some music to some of my pages but just using plain html coding or the little harder javascripting encoding is not what i want to do.
What you're going to want to do is look up the header function on PHP.net. Here's how you download a PDf for example:

Code:
<?php // We'll be outputting a PDF header('Content-type: application/pdf'); // It will be called downloaded.pdf header('Content-Disposition: attachment; filename="downloaded.pdf"'); // The PDF source is in original.pdf readfile('original.pdf'); ?>
(from php.net)

You can perform other steps before initiating the download such as verifying a user session, etc. Just make sure to place the files in a non-web-accessible location and you should be good to go.
We need less Democrats and Republicans, and more people that think for themselves.

infinite expanse
     
jay3ld  (op)
Senior User
Join Date: Jul 2004
Status: Offline
Reply With Quote
Jan 27, 2006, 06:54 PM
 
ahh so mp3 would follow

Code:
<?php // We'll be outputting a PDF header('Content-type: application/mp3'); // It will be called downloaded.pdf header('Content-Disposition: attachment; filename="Sone Name.mp3"'); // The PDF source is in original.pdf readfile('Songname.mp3'); ?>
then in the page i do

Code:
<embed src="music.php" autostart="True" loop="True"></embed>
     
york28
Senior User
Join Date: Mar 2002
Location: Chicago, IL
Status: Offline
Reply With Quote
Jan 30, 2006, 04:58 AM
 
I would try it but I think that looks right. To be honest I'm really not up on my EMBED tags these days.
We need less Democrats and Republicans, and more people that think for themselves.

infinite expanse
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 09:33 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,