Link to home
Start Free TrialLog in
Avatar of qazs
qazs

asked on

Playing music file and hide file's path

Hi,
How can I users listen to a music file but not letting them know the path to the music file?
Can this be done in cgi? Thanks very much.
Avatar of ahoffmann
ahoffmann
Flag of Germany image

write a CGI script which reads the music file and writes it as response with a proper HTTP header
best if the music file is located outside DocumentRoot of your web server
Avatar of qazs
qazs

ASKER

Thanks. But how do I read a music file? I only know how to read an image file.
Can you direct me to some online articles or tutorials regarding this? I can't seem to find any.
you read a music file simply as binary data
Avatar of qazs

ASKER

Is it something like this:
print $query->header(-type=>'audio/x-mp3');
#print $query->header;
$dir = '/music_folder/';
$ext = 'mp3';
open (FILE, "$dir$music_file.$ext") or die "Can't open music file";

binmode FILE;
while(read(FILE, my $buf, 512)){
      print $buf;
}
ASKER CERTIFIED SOLUTION
Avatar of ahoffmann
ahoffmann
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of qazs

ASKER

Hi,
another thing.
I'm not sure about what you mean by:
"best if the music file is located outside DocumentRoot of your web server".

Can you explain what you meant?
Will others still be able to find the exact path of the music file if I put it in a sub directory, but using cgi to play it?
assuming your static html files are served from /path/to/docs then this is the DocumentRoot.
You have your CGIs then served from for example /path/to/cgi-bin (sometimes known as ProgramRoot or script directory), which cannot contain static html files.
Both directories are configured in the web server, and the client access this then using an URL like:
  http://your.tld/static.html
which will result in delivering /path/to/docs/statisc.html. Same for cgi-bin.

Now place your data files in for example /path/to/data, which is initially unknown to the web server, but you CGI can access it. This way it cannot be access through URL, even if the lient knows the full path. Some kind of a second line of defence.
Avatar of qazs

ASKER

Ok... another problem here.
The script works alright with Windows Media Player, but plays awkwardly in Quicktime.
In Quicktime, it just plays a small portion of it. It's like loading a small part of the song and playing it.
Any idea how to fix it?
sounds like there is something different with the HTTP header, I guess a quicktime problem
Avatar of qazs

ASKER

hi,
I've a very serious problem here.
I'm able to hide the music file's path and let users hear the song in Internet Explorer. It just opens up the Windows Player and plays the music from the source, eg:
http://url.com/cgi-bin/music.cgi?file=xyz

Ok, but in Mozilla, it prompts the user to open the file, and then download a copy of the file in the temp folder!

Is there a way to prevent Mozilla Firefox from doing this?
> Is there a way to prevent Mozilla Firefox from doing this?
either Firfox needs to add the proper MIME type, or you need to sedn a MIME type which is known by default by Firefox
Avatar of qazs

ASKER

Thanks. I found a solution by using m3u file.