Welcome Guest, Not a member yet? Register   Sign In
Filtering special characters for URL segments
#1

[eluser]Christophe28[/eluser]
Hi,

I'm creating an app using CodeIgniter.

When users want to upload an image, I'd like to use the title of the image (without extension) as the second segment of the url. But I have noticed when I upload a testphoto with a name like Nirvana_(2).jpg I got an error when surfing to mydomain.com/photos/nirvana_(2)/ because the URL contains characters like ()

Is there a special function in CodeIgniter (or PHP) which filters all characters, except a-z, numbers, underscores and dashes?

So following the above example, a function which create 'Nirvana_2' instead of 'Nirvana_(2) ?

Thank you!

Christophe
#2

[eluser]LuckyFella73[/eluser]
Have a look here: application/config/config.php

Code:
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';

I'm not sure if you can do this like wanted because the
second URI segment is the function/ method of the controller
so if you have your url like in your example:
Quote:mydomain.com/photos/nirvana_(2)/

CI will look for controller "photos" and function "nirvana_(2)"

You could move the image name to the 3. URI segment and display
your images using some kind of "display-function" which uses
the 3. URI segment for buiding the correct path/img-name.
#3

[eluser]Christophe28[/eluser]
Hi,

I'm aware of the config permitted uri chars, but for security reasons I don't want to edit those.

I just gave a url example. My url is different Wink

But like said, I search a nice PHP function which filters every character, except a-z, 0-9, -, _ Does anybody knows a function like this or a regex?

Christophe




Theme © iAndrew 2016 - Forum software by © MyBB