Welcome Guest, Not a member yet? Register   Sign In
Avoiding URL Forbidden Characters By Using urlencode()?
#9

[eluser]Matt Egan[/eluser]
Here is my "download" function inside my "project" class. Pretty simple.

Code:
function download()    {
    
    if($this->projectPoint->loggedIn())    {
        
        if($this->projectPoint->downloadFile())    {
            
            redirect('project/index/'.$this->session->userdata('projectDirectory'));
            
        } else {
            
            $this->session->set_flashdata('message', 'sorry, there was an error downloading your file');
            
            redirect('project/index/'.$this->session->userdata('projectDirectory'));
            
        }
        
    } else if($this->uri->segment(3) != "")    {
        
        redirect('project/login/'.$this->uri->segment(3));
        
    } else    {
        
        redirect('create/index');
        
    }
    
}

Inside my model, I have two functions that aid in downloading of the file the first is the "downloadFile" function. Again, this is where I am encountering my problems. This works and the file is downloaded if the file doesn't contain any funky characters..

Code:
function downloadFile()    {

    $this->load->helper('url');
    $this->load->helper('download');
    $this->load->helper('file');
    
    $filename  = urldecode($this->uri->segment(4));        
    
    if(!$data = file_get_contents(base_url().'projects/'.$this->session->userdata('projectDirectory').'/'.$filename))    {
        
        return FALSE;
        
    } else{
        
        force_download($filename, $data);

        return TRUE;
        
    }
    
}

Here is the function inside my model that generates links to download the file, "downloadLink" The global variable "files" is a query row of the files database. It creates a link that looks like this - "../index.php/project/download/projectname/filename. extension"

Code:
function downloadLink()    {
    
    $this->load->helper('url');

    echo site_url('project/download/'.$this->session->userdata('projectDirectory').'/'.urlencode($GLOBALS['files']->fileFilename));
    
}

Here is a sample url.

Code:
http://localhost/projectpoint/index.php/project/download/wolff/21_fix_you__coldplay_(1).pdf

I haven't added or taken away from any of the allowed characters Codeigniter came with. I get this error.

Code:
The URI you submitted has disallowed characters.

This is strange, the URI I am submitting does not have any disallowed characters, it does, but they are encoded, the filename is "21_fix_you__coldplay_(1).pdf" so unencoded, it does contain disallowed characters. If I add parenthesis to the allowed characters, I then get this error.

Code:
Message: file_get_contents(http://localhost/projectpoint/projects/wolff/21_fix_you__coldplay_(1).pdf) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found

This is also weird, where did those odd characters come from in the filename, I've echoed out the decoded filename and passed it into the function, and it does the same thing, even though the decoded filename is returned correctly. I'm really stumped here. Any ideas? Again, it all goes down without a hitch if my file contains only characters that Codeigniter allows....


Messages In This Thread
Avoiding URL Forbidden Characters By Using urlencode()? - by El Forum - 02-03-2010, 11:20 AM
Avoiding URL Forbidden Characters By Using urlencode()? - by El Forum - 02-03-2010, 12:04 PM
Avoiding URL Forbidden Characters By Using urlencode()? - by El Forum - 02-03-2010, 12:25 PM
Avoiding URL Forbidden Characters By Using urlencode()? - by El Forum - 02-03-2010, 12:43 PM
Avoiding URL Forbidden Characters By Using urlencode()? - by El Forum - 02-03-2010, 01:20 PM
Avoiding URL Forbidden Characters By Using urlencode()? - by El Forum - 02-03-2010, 01:27 PM
Avoiding URL Forbidden Characters By Using urlencode()? - by El Forum - 02-03-2010, 02:23 PM
Avoiding URL Forbidden Characters By Using urlencode()? - by El Forum - 02-03-2010, 02:24 PM
Avoiding URL Forbidden Characters By Using urlencode()? - by El Forum - 02-03-2010, 07:25 PM



Theme © iAndrew 2016 - Forum software by © MyBB