Jump to content

Hide an mp3 file with PHP?


amites

Recommended Posts

Hello,

 

This one is stumping my blain, hoping I can draw upon some help here,

 

I am building an application that will allow users to preview an mp3 file in a flash player,

question is, can this be done without using

    header(location: URL)

 

I'd like to hide the mp3's outside of the public_html folder, don't have to but I would like to

 

any ideas?

 

I'm building this using the Code Igniter framework if that makes a difference to anyone's thought process

 

 

Link to comment
Share on other sites

The flash application should not care where the MP3 file is located. I am not sure how that software works etc, but yea should be possible. However if you want them to be able to download it you may want to store the mp3s with a randomly generated hash for the file name, then use the DB to have them download with the original name etc.

 

At least that is my 2 cents. But yea the flash player should not care where the MP3 is as long as you give it the correct path.

Link to comment
Share on other sites

As seen in the header page in the PHP manual:

<?php
$filename = "theDownloadedFileIsCalledThis.mp3";
$myFile = "/absolute/path/to/my/file.mp3";

$mm_type="application/octet-stream";

header("Cache-Control: public, must-revalidate");
header("Pragma: hack"); // makes it no-cache basically
header("Content-Type: " . $mm_type);
header("Content-Length: " .(string)(filesize($myFile)) );
header('Content-Disposition: attachment; filename="'.$filename.'"');
header("Content-Transfer-Encoding: binary\n");

readfile($myFile);

?>

 

I haven't tested it 100%, but I'm pretty sure it works. Basically it just takes the mp3, and echos the contents to this page - which since you sent the headers saying it's a mp3 and not a page.... it'll play the song.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.