CodeIgniter Forums
File name - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: File name (/thread-45223.html)



File name - El Forum - 09-13-2011

[eluser]Unknown[/eluser]
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:
Code:
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Downloads extends CI_Controller
{
    public function index()
    {
        
    $this->load->helper('download');
    $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.