Reputation: 1355
I need to pass filenames via the url, e.g.:
http://example.com/images/niceplace.jpg
The problem I'm having is when the file name contains a blank character, e.g.:
http://example.com/images/nice place.jpg
or
http://example.com/images/nice%20place.jpg
For these two URLs, codeigniter complains about the blank char: "The URI you submitted has disallowed characters."
How should I go about fixing this?
I know I can add the blank character to the permitted_uri_chars
in config.php
but I'm looking for a better solution as there might be other disallowed characters in a filename.
Upvotes: 1
Views: 2889
Reputation: 462
One of the better way to work with url's for specified condition is to encode/encrypt your url parameters using encryption/security class in order to maintain URL security:
$encrypt=$this->encrypt->encode($param1) & $this->encrypt->decode($encrypt)
Alternatively if you want special chars to be allowed in the URL then change your config settings in config.php file.
File Location: application/config/config.php
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
Add all characters in right side that you want to be allowed with your application.
Upvotes: 0
Reputation: 1355
I figured out a solution.
The URL is generated using rawurlencode()
.
Then, within the images
controller, the filename is decoded using rawurldecode(html_entity_decode($filename))
.
I successfully tested this solution with a few special characters I can think of and with UTF-8 characters.
Upvotes: 1
Reputation: 6718
This configuration option is created to avoid some characters being passed in URI and you want to walkaround it in some cases. I think most appropriate solutions are:
Upvotes: 0
Reputation: 138
You can use this method:
Actually, you will run into another issues, when a filename would contain &
character, and a few others. urlencode would get rid of all the possible issues.
Upvotes: 0