1

I am running a SocialEngine PHP application, which i've recently migrated to another server.

And from that point on - a problem occurs:

The SocialEngine's core trying to include files in case insensitive paths, which appear not to exist (although, in the right case, they do exist)

How can I make the PHP/Apache act nicer, and also search in other cases?

For example, the SocialEngine looks for /application/modules/Menuitems.php, and the right path is /application/modules/Menu**I**tems.php.

To sum up: I want case-insensitive paths!

hakre
  • 193,403
  • 52
  • 435
  • 836
imriqwe
  • 1,455
  • 11
  • 15
  • 4
    Welcome to SO. Please see the FAQ about what kind of questions to ask. Only because you want something does not mean that you've got a question. Secondly, you need to do some basic stuff on your own, e.g. get a computer class about the server operating system you copied the application over to to learn more. – hakre Oct 30 '11 at 22:47
  • Were you on a Windows server before or something? Pretty much every path on *nix systems is case-sensitive. – Amber Oct 30 '11 at 22:47
  • If you've migrated from a Windows host to a Linux host you're probably going to be out of luck. It is the operating system resolving those file paths, not PHP, and generally, non-Win file paths are case sensitive. – Michael Berkowski Oct 30 '11 at 22:47
  • http://stackoverflow.com/questions/3964793/php-case-insensitive-version-of-file-exists – Steve Oct 30 '11 at 22:48
  • hakre, what do you want? I hate those who try to teach a lesson by talking like experts... – imriqwe Oct 30 '11 at 22:52
  • I asked a questions, what is your problem? – imriqwe Oct 30 '11 at 22:53
  • 3
    @Imri: That's why I suggested you visit a computer class. The computer you copied the files to most certainly will not have what you want. Learn about it, live with it. But nobody can change it. – hakre Oct 30 '11 at 22:54
  • Don't tell me to take a computer class, because if I could do it, I would. I don't need your irrelevant advices. If you cant, or don't want to specifically help me, just do not reply here. – imriqwe Oct 30 '11 at 22:59
  • hei there @Imri, those hate attitude doesn't accepted here, in SO. This is free service and WE voluntarily help PEOPLE like you. Further more, your problem is caused by the difference in how each OS is working internally in regard of file path. If you don't know it, follow Hakre suggestion, get computer class or learn the OS you are using to understand it. Again, we work voluntarily. – ariefbayu Oct 30 '11 at 23:30
  • Thank you for your answer. I didn't intend to try to demand anything. But I just don't realize why, on my first-ever question, he is attacking me. Maybe I don't have the required knowledge to solve the problem, but he could explain that I am not asking well. If there was a class related to this issue, i would take it. Thanks, again, for your reply. – imriqwe Oct 30 '11 at 23:40
  • What @hakre was meaning was that you need to understand how file systems understand paths, which is different among each OS type (in many cases). That means you're missing a key point of view that is making this particular problem difficult to solve. Some OSes require exact case, some don't, but you need to understand the difference if you're going to migrate your code from one to another. – Jared Farrish Oct 31 '11 at 00:10
  • 2
    @hakre - Not sure if you're having a bad day, but that was a counter-productive comment. You don't usually respond that way, and I usually enjoy reading your responses, so I assume you're having a not-so-great day. I don't think the OP meant anything by it. `:)` – Jared Farrish Oct 31 '11 at 00:12
  • @hakre - I have never taken a "computer class" in my life, and I suppose you could impeach me on my "computer knowledge", the OP may not understand everything related to the problem. I guarantee you the OP doesn't understand SO if they're new (who really does?). If you know something, provide an answer, if not, c'mon. Be kind. We were all there at one time. – Jared Farrish Oct 31 '11 at 00:20
  • 1
    @hakre - You don't need a computer course to understand how a file system accesses a path, you just need knowledge. This site is about answers to questions. The OP's level of understanding is, to be honest, secondary to that. – Jared Farrish Oct 31 '11 at 00:32
  • 1
    @JaredFarrish: I now decided to add an answer instead, it was just a comment, I'm sorry if that was offending to anyone, was not meant that way. – hakre Oct 31 '11 at 11:50

3 Answers3

5

You have case insensitive paths in windows. But when you move your page to linux path will be case sensitive. You can make function for build path that convert all letters to uppercase or lowercase (often preferred) and use one of these normalized naming styles for directory- and file- names.

Scott C Wilson
  • 19,102
  • 10
  • 61
  • 83
radeklos
  • 2,168
  • 21
  • 19
0

You can experiment with this code I have left only a couple of TODO steps (sorry! have no time.. and it is too big to put it as a comment) you can complete. You put this code at the very begining of the index.php file and every time an include fails the correctFile name is called.

You have to test it separately though as it gets the file name from the warning that php returns. My php version return the file name in parentheses don't know yours. Test the code to see how it works.

<?PHP
/*****************put this at the very top*********************************/
 $flag=2; 
 function correctFileName($incorrectFileName)
 {
    //directory and file to look at/for
    $dirToLookAt = dirname($incorrectFileName);
    $fileToLookFor = basename($incorrectFileName);

    //get all .php files
    $files = array(); $directory = opendir($dirToLookAt ); 
    while($item = readdir($directory)) 
        if(is_string(strstr($item,'.php')))
            $files[] = $item; 

    //to do
    /*
    loop through the $files array and to 
    a case insensitive search for $incorrectFileName

    if you find one then rename the file you found to $incorrectFileName

    then break the loop
    */

 }
//error handler function
function customError($errno, $errstr)
  {
        global $flag;
        //find the file name
        if($errno==2 and (($flag%2)==0))
        {
              //this will allow to enter only once per time
              $flag++;
              //get the file name
             $start = strpos($errstr, '(') +1;//7
             $length = strpos($errstr, ')') -  $start ;//10
             correctFileName(substr($errstr, $start  ,$length));
        }
  }

//set error handler
set_error_handler("customError");
/*****************************************************************/

//trigger error
include 'c:\www\home\122221.php'; 
?>

Also the code makes the assumption that the directory part-name is correct! otherwise you have to mnage that too.

Melsi
  • 1,462
  • 1
  • 15
  • 21
0

As already talked about in the comments (I'm sorry if you felt offended, was not meant that way) above and the one given answer there is a fundamental problem:

The filenames the application is using are invalid. They were not on your windows system, but they are on linux.

This is hard to solve. However I had the following idea: PHP StreamWrapper.

Stream Wrappers interoperate between filenames and the underlying code. They enable to access URLs and files with the same interface, e.g. include or file_get_contents.

Normally the type of stream (and onto which you can register your own wrapper) start with something like protocol://.

If no protocol is given, it is file://.

So what you can try is to create your own stream-wrapper that registers onto the file:// protocol. You can then deal with the problems of the case-sensitivity.

The manual provides a pre-made definition of a stream-wrapper-class you might want to re-use.

Others have given hints and code how to resolve case-sensitivity problems. You normally only need to deal with read operations in your case.

Community
  • 1
  • 1
hakre
  • 193,403
  • 52
  • 435
  • 836