Re: Regular expression for check that an entered filename is valid



On 19 Dec, 16:51, "Steve" <no....@xxxxxxxxxxx> wrote:
"Toby A Inkster" <usenet200...@xxxxxxxxxxxxxxxxx> wrote in messagenews:hoqn35-hv3.ln1@xxxxxxxxxxxxxxxxxxxx



Captain Paralytic wrote:

How do you define a valid filename?

Good question. As far as I know, for Linux and most UNIXy OSes it's this:

#[^/]#

i.e. any string that doesn't contain a slash is a valid filename. (Because
of course, the slash must be a directory separator.) Any other character
is valid in a file name -- asterisks, question marks, colons, tabs, line
feeds, whatever. Names "." and ".." are technically allowed, but they
always already exist.

It does depend on the filesystem though. Linux supports dozens of
different filesystems and some of those will limit you further.

Windows is a more fussy. As well as slashes, it doesn't allow colons,
backslashes, asterisks, question marks, whitespace other than the space
character itself, less-than and greater-than signs, double quotes and the
pipe symbol. There are also a small number of reserved file names that
cannot be created, such as "CON", "PRN", "CLOCK$" and "LPT1" -- these
special filenames were used to represent various hardware devices in DOS.

with the exception of CLOCK$ on win >= xp, you're exactly right...and i'm
glad i'm not the only one geeky enough to know that. :^)

Actually, you can create these files using some programming languages
- and get up to all sorts of mischief as a result (not least because
MS Windows doesn't let you delete them)

I'd go with is_writeable(realpath($filename)) (of course that doesn't
stop people writing files where they shouldn't.

C.
C.
.



Relevant Pages

  • Re: JSP Internationalization
    ... fixed it for me was to make sure that my Oracle database was in the ... correct character set, Oracle 9i did not use the standard UTF-8 unless ... I still get question marks. ... The native resource file is saved as UTF 8. ...
    (comp.lang.java.programmer)
  • Re: Absolute positioning between browsers
    ... Why use tick.png when there's a perfectly good character for doing ... even View Source showed question marks. ... "Ticks" are nasty little blood-sucking parasitic arachnids. ... my browser, please. ...
    (comp.infosystems.www.authoring.stylesheets)
  • Help with Macro to Change Font Color
    ... I'm looking for a macro that will search a Word document ... for a given character. ... zero asterisks to hundreds of asterisks within a single document. ...
    (microsoft.public.word.vba.beginners)
  • XP Pro - logon password conceal character
    ... During XP login, the password entered is normally concealed by a series of ... asterisks. ... Something on my system changed this character to a rectangular ...
    (microsoft.public.windowsxp.newusers)
  • Re: help in my project
    ... Thank you Dave, I had noticed the asterisks as well and I had read ... somewhere in a post that it signified bold text. ... > escape character or just an HTML interpretation. ...
    (microsoft.public.excel)