Re: Ignoring Case on directories [message #171346 is a reply to message #171170] |
Thu, 30 December 2010 14:47 |
Twayne
Messages: 135 Registered: September 2010
Karma:
|
Senior Member |
|
|
In news:ceedc79d-bad7-4e16-830b-8ea5e55b6034(at)s5g2000yqm(dot)googlegroups(dot)com,
jwcarlton <jwcarlton(at)gmail(dot)com> typed:
> I think that the answer to this is "no", but I thought I'd
> ask :-)
>
> I'm wanting to open a file where the directory path is
> given by the user. For example:
>
> if (is_file("/path/to/" . $_GET['directory'] . "/file.txt"))
> $example = FILE("/path/to/" . $_GET['directory'] .
> "/file.txt");
>
> else
> // return error
>
> // please ignore any typos; I just typed this up here for
> the example
>
> The thing is, the directory path could be, say,
> /path/to/SomeDirectory/ file.txt, but the user could enter
> "somedirectory"; in which case, they would get the error.
>
> Currently, I keep all of the directory names in a MySQL
> database, then before opening file.txt, I search for the
> directory in MySQL (which is case insensitive), then load
> the path based on the name in the database instead of
> what's given. But during peak hours, this method can result
> in several hundred MySQL queries per minute.
>
> Before this, I just used opendir to load all of the
> directories into an array on the fly, then did a case
> insensitive search through the array. But, when I started
> having 90,000 directories (30,000 in 3 separate parent
> directories), this was considerably slower than using MySQL.
>
> So, the MySQL search works, but the question is, can PHP do
> a directory lookup that's case insensitive; and,
> preferably, return the case-correct directory name?
PHP can force everything to lower case for you during the ftp upload; is
that what you mean? Otherwise IMO it's a matter of just being consistant in
a way that's easy to remember & repeat. I don't like all lower case, so I
use a cap for the first letter of each term; e.g. ..MySite, OnThisPage,
etc.. Some people use underscores instead; that's a good design too and used
by many. Just pick a method, and stick to it. "There's always time to redo
it later" is not a good philosophy; do it right the first time.
HTH,
Twayne`
|
|
|