• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Uploading / Secure Download + Steaming!

#1
[eluser]shenanigans01[/eluser]
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.

-Mike

Code:
// (...) 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)) {
    $this->load->helper('download');
    $data = file_get_contents($file);
    force_download($filename, $data);
}
else {
    show_error('Sorry, this file does not seem to exist');
}

#2
[eluser]Krzemo[/eluser]
BLOB type in DB for storing mp3 files might be a solution

#3
[eluser]shenanigans01[/eluser]
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.

#4
[eluser]Krzemo[/eluser]
"premature optimization is the root of all evil" Smile


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.