Welcome Guest, Not a member yet? Register   Sign In
Uploading / Secure Download + Steaming!

Hello, I'm working on a project where a user will upload a .mp3 file. Once the file is uploaded it will be renamed, and the name will be saved in a database. I have the following code for downloading the file which I found here on the forums: which will have the .mp3 files stores outside of the htdocs folder on the server to prevent people from accessing the file as it needs to be secure. My question is the following: Is there anyway to have the .mp3 file outside of the webroot, but still able to stream it to a flash .mp3 player? Is there anything in CI currently that could be used to accomplish that. Any idea's anyone has would be amazing. The goal is to offer a download that will have an expiring link once someone purchases the .mp3 file... but we want to allow the user to hear it before hand. If anyone has a better solution on how to get this up and going I'm all ears and hear to learn. thanks.


// (...) do something to authenticate visitor

// Fetch download filename from database
$filename = $this->downloads->fetch((int) $this->uri->segment(3))
$file = '../downloads/' . filename ;

// Read file contents and force download
if (file_exists($file) && is_file($file)) {
    $data = file_get_contents($file);
    force_download($filename, $data);
else {
    show_error('Sorry, this file does not seem to exist');

BLOB type in DB for storing mp3 files might be a solution

I was thinking that at first, but the problem is that there are going to be 10k + .mp3 files so that might be a little big for the database, loadtimes, backup's etc.

"premature optimization is the root of all evil" Smile

Theme © iAndrew 2016 - Forum software by © MyBB