CodeIgniter Forums
File name - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: File name (/thread-45223.html)

File name - El Forum - 09-13-2011

Hi I am trying to get the file name from the URL to pass it to force_download() function how do i do that?

Here is how the url looks base_url('downloads/file1.mp3'). When i click on the file name i get 404 page not found. I have the download.php which includes the following code:
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Downloads extends CI_Controller
    public function index()
    $data = file_get_contents('./application/views/uploads/file1.mp3');
    $name = 'file1.mp3';
    force_download($name, $data);

Now instead of file1.mp3 in the file_get_contents('./application/views/uploads/file1.mp3') i want to store the name portion in a variable $fileName and then pass it to file_get_contents.

Thanks in advance.