Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hey guys, real quick one, I am heling my friend with his band site, how can i make a directory that will store their songs but wont let anyone access them, they are worried people will try and download them for free. Any ideas?

You will need to create a directory OUTSIDE the webroot. For example, if the webroot is C:\websites\mysite then create a folder such as C:\websites\music.
If you are on a shared host you will have a root folder for ALL of your content. You will want to create a sub-folder in that folder for the web root of the site and point the domain to that sub-folder. Then have a different sub-folder for the music.
Ex:
\\RootFromHost\website (for the site)
\\RootFromHost\music (for the music files)You will want to set the appropriate permissions ont he music folder as well to prevent access.
Then if you want users to access those files through the website you will need to use a server-side language to "read" the files and server them to the users browser. I would suggest storing the details of the music files in a database and just passing the ID of a file to allow the suer to play the file.
You would want a "playmp3.php" page (or something similar). That page could look something like this:
<?php
$id = $_GET['id'];//Query db for the path of the selected file
$query = "SELECT name, path FOM music WHERE id = $id";
$result = mysql_query($query);
$record = mysql_fetch_assoc($result);
$name = $record['name'];
$path = $record['path'];//Send the mp3 file to the user's browser
header("Content-Type: audio/mpeg");
header("Content-Disposition: inline; filename=$name");
echo file_get_contents($path);?>
NOTE: The headers settings might not be 100% correct. I did a quick modification on an existing script Ihave to server an m3u (playlist) file to the browser. But, that is the general idea.
Michael J

Hi Michael, I have never worked with music files before. I am creating a panel where they can upload music through it. I am limiting it to 6 songs becuase they dont have a lot of space and dont want to give too much up (hopefully they can sell their music at some point). Anywyas, how do i make it so they can upload it from a panel to the directory you mentioned (which I have created) and then play it on their site. I assume I will need a music player, do you know of any free ones and how do they work. I have learned a lot over the years but this is new to me. Thanks

I'm going to punt this one:
There's way too many issues going on in that question. You need to break down the process into manageable chuncks and attasck each one separately. First work on an upload process (many tutorial/guides available). Saving the file to a directory not in the web root is no different than one that is.
Michael J

Hey Michael,
I have just about figured this out. I have the directory and the form to load the music and now I am working on the player. I have come across something else that I hope will help me but even tough I have done a lot of reading on it I am confused how to get it going. I want to set a cookie so when someone logs in I dont have to keep passing info through post. I figure I will need to cookies, named 'type' and 'id', and i want them set for 2 hours. I understand the cookie part but cant figure out where to set it. Any info would be appreciated. This is for my login script by the way.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |