PHP Autoload ignorecase

Is there a way to call require_once with some "case insensitive flag"? On windows, this is fine, but linux is case sensitive. Is there a way to override? Thanks

+4
source share
3 answers

Of course download

strtolower($className . ".php") 

and name your files lowercase.


No matter how you try to upload your files, only the lowercase version will be downloaded.

+2
source

You can use it every time you load, you automatically load the corresponding classes. You need to change directories, depending on your project. you can echo or print_r print which classes are loaded every time you call something. also, all your class names should have the same format, for example, className.class.php, for example Dashboard.class.php, Category.class.php. You can use ucwords to make first capital letters.

 function __autoload($className) { if (file_exists(__DIR__ . '/../library/' . strtolower($className) . '.class.php')) { require_once(__DIR__ . '/../library/' . strtolower($className) . '.class.php'); } else if (file_exists(__DIR__ . '/../application/controllers/' . strtolower($className) . '.php')) { require_once(__DIR__ . '/../application/controllers/' . strtolower($className) . '.php'); } else if (file_exists(__DIR__ . '/../application/models/' . strtolower($className) . '.php')) { require_once(__DIR__ . '/../application/models/' . strtolower($className) . '.php'); } } 
0
source

Just include the .php header or some other shared file somewhere else in you.,

 <?php $filename = basename($_SERVER['SCRIPT_FILENAME']); $request = basename($_SERVER['SCRIPT_NAME']); if($filename != $request) die('Case of filename and request do not match!'); ?> 

I think this can help you solve your problem. also link to the following location https://superuser.com/questions/431342/linux-both-case-sensitive-and-case-insensitive-and-always-inconvenient

0
source

All Articles