views:

65

answers:

3

im' trying to make a file based article system and i want the folders to be my categories and files inside it to be the actual articles. But sometimes i need some special characters in my folder/file name(\/:*?",and actually i'm interested just in double quotes and question mark). Is there a way to do the trick...something like & is in html or something like this. thanks

+1  A: 

There are only few special characters which aren't allowed in file names. so keep your own insanitized sequence for those characters. For instance, replace all '?' with '#quest' before creating files and so. Do the reverse when you read them, aint this good? Insanitized means some combination of characters that we don't type usually like '#quest'.

pMan
this is an interesting idea, but how my url will look like then?and how friendly for search engines is that?
kmunky
when you read the file just do the reverse of it, like replace all '#quest' to '?' so your URLs will be fine. I think thats what you asked?
pMan
oh yeah, right...actually it's very easy ;) it's all based on "encode"/"decode", thanks @pMan
kmunky
+3  A: 

Short answer: Your operating system could support such file names, but it doesn't seem to.

There isn't a simple way for you to do something easy like & for this. You could store the real filename, or make a conversion table such that something like _____questionmark_____ converted into that symbol or something silly like that, but then you run into problems with that particular string.

Fundamentally though, you should store the title separately from the file itself. A database would be an appropriate location.

At a deeper level, if you're asking a question like this, I think it's safe to say that allowing users to specify filenames on your system is likely to be a large security risk.

Paul McMillan
those users will have administrator privileges(just a few users). what i don't understand is this mixed file and database...
kmunky
It's simple: You can't reasonably store the title you want to use as a valid filename, so you have to store it somewhere else. Your titles won't generate valid URLs either. You might do well to look up various "slug" functions for converting strings into URL friendly formats. As a bonus, they can be stored on the disk with that as the filename too.
Paul McMillan
A: 

I would recommend using a .htaccess file to pass the "filename" as an argument to your PHP script. Subsequently have the script look up the article in a database lookup table that points to the article file.

Paul Lammertsma