Computing.Net > Forums > Web Development > creating a directory

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

creating a directory

Reply to Message Icon

Name: BigShow
Date: September 21, 2008 at 18:52:16 Pacific
OS: xp
CPU/Ram: 1 gig
Product: dell
Comment:

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?



Sponsored Link
Ads by Google

Response Number 1
Name: Michael J (by mjdamato)
Date: September 22, 2008 at 09:29:20 Pacific
Reply:

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


0

Response Number 2
Name: BigShow
Date: September 22, 2008 at 15:49:48 Pacific
Reply:

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


0

Response Number 3
Name: Michael J (by mjdamato)
Date: September 22, 2008 at 19:58:08 Pacific
Reply:

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


0

Response Number 4
Name: BigShow
Date: September 26, 2008 at 20:19:56 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: creating a directory

creating a link directory www.computing.net/answers/webdevel/creating-a-link-directory/3536.html

creating a youtube like page www.computing.net/answers/webdevel/creating-a-youtube-like-page/3631.html

how do I create a search option www.computing.net/answers/webdevel/how-do-i-create-a-search-option-/3057.html