Welcome Guest, Not a member yet? Register   Sign In
file_helper: read_file issues with filename including brackets
#1

[eluser]RBrowne[/eluser]
I've been trying to use the read_file function of file_helper, which works for the most part. However whenever there is a ( in the filename, the function fails to be able to read the function.

I've checked the allowed chars in the url - not that. Checked the file exists - it does. Tried urlencode/decode/recode and they don't help.

Here's my function for the downloader:
Code:
function index() {
    $this->load->helper('download');
    $this->load->helper('file');
    $aSegs = $this->uri->segment_array();
    //print_r($aSegs);
    switch ($aSegs[2]) {
        case 'po':
            $oData = read_file('./pdfs/purchase_orders/' . $aSegs[3]);
            break;
        case 'inv':
            $oData = read_file('./pdfs/invoices/' . $aSegs[3]);
            break;
        default:
            $oData = FALSE;
            break;
    }
    $sName = $aSegs[3];
    //print_r($oData);
    if ($oData !== FALSE) {
        force_download($sName, $oData);
    }
}
I've checked that the $aSegs[3] is correct - it is. The example url is: localhost/download/po/Purchase Order 100542 - PR Electronics (UK) Ltd.pdf

Does anyone have any ideas? I don't really want to write a function to strip the brackets out of the naming function, as this would be a pain.

Any help would be greatly appreciated.

Rich
#2

[eluser]Dam1an[/eluser]
The file reading is actually taken care of by the PHP method file_get_contents so the error is likely to come about there...

The way I always handle files is:
1) When a file is added, give it a unique name made up of letters, numbers and underscores (all safe characters)
2) Add a row in the database which maps the original file name to the one on disk
3) When there is a request for the file (either by the real name or the name on disk) find its location in the database table and pass that into the force_download helper
#3

[eluser]TheFuzzy0ne[/eluser]
Try escaping the bracket with a double-backslash. You'll probably need to do that with spaces and other special characters ("'\-) and so on.




Theme © iAndrew 2016 - Forum software by © MyBB