Welcome Guest, Not a member yet? Register   Sign In
Rerouted route and output headers
#1

[eluser]Unknown[/eluser]
I swear this was working a few hours ago but now it's not

I have an old website where people can download levels for an old video game. They would normally go to the url

http://mydomain.com/maps/filename.zip

I've since re done the site in codeigniter

the correct url now is

http://mydomain.com/downloads/maps/filename.zip

However, in case they use outdated links I added an override in my routes

Code:
$route['maps/(:any)'] = "downloads/maps/$1";

What im trying to do is store the file into a variable, do some logging in the database and then send the file to the output buffer so that it downloads it

Everything works fine when i access the route directly by going to
http://mydomain.com/downloads/maps/filename.zip

But when i access the alias (mydomain.com/maps/filename.zip) it still goes into the correct controller and method but chokes on the output part. For instance i can debug with var_dumps and it works all day but when i try to output the file i get errors

Chrome: Error 6 (net::ERR_FILE_NOT_FOUND): The file or directory could not be found.
IE: Asks to open or save then says the file cannot be opened/saved
FF: Firefox cannot find the file

My downloads function looks like this
Code:
function maps($filename=null)
{
        $this->load->model('mapsmodel', 'maps', true);
        $data['filename'] = $filename;
        $file = $this->maps->get_by_file_name($data);

        if($file == null)
        {
            $read = file_get_contents('http://mydomain.com/map/'.$filename);
            if(substr($read, 0, 2)!='PK')
            {
                redirect(base_url('gmd/mapnotfound'));
                return;
            }
        }
        else
        {
            $read = file_get_contents($file[0]->link);
            $this->log_download('map_downloads', $file[0]->map_id, $this->maps);
        }
        $this->output->set_content_type('application/zip');
        $this->output->set_output($read);
}
#2

[eluser]Unknown[/eluser]
I'm now getting around it by setting up a controller called maps and putting redirect logic in the constructor

Code:
class Maps extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->load->helper('url');
        $uri = uri_string();
        $map = explode('/', $uri);
        $map = $map[1];
        redirect(base_url('downloads/maps/'.$map));
    }
}

If anyone knows how I can do it the way I want in the post above then please let me know

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB