1

I have a weird problem.

file_exists('/home/1/w/bla/www/bla')

I'm on a Windows server, and this returns true! The dir obviously doesn't exist on a Windows server. Anyone know why?

JamesB
  • 187
  • 3
  • 19
  • 1
    What's the return of `realpath('/home/1/w/bla/www/bla')` ? – Gwendal Feb 05 '16 at 11:38
  • Aha! It's C:\home\... The script was supposed to create the directory if it didn't exits, but only on the linux server, but looks like it managed to create that directory on Windows as well. I was sure these functions would fail if paths werent 100% correct (meaning it would have to start with "C:\") – JamesB Feb 05 '16 at 11:41
  • PHP is smart enough to convert path between windows and linux – Gwendal Feb 05 '16 at 11:45
  • But is there any way to prevent this behaviour? I don't want mkdir('/dfh/sdfkjh/') to work on Windows. – JamesB Feb 05 '16 at 12:00
  • You can't really prevent it from working because it's a native behavior but you can add a if statement to check if you are on linux or windows and then adapting your path http://stackoverflow.com/questions/5879043/php-script-detect-whether-running-under-linux-or-windows – Gwendal Feb 05 '16 at 12:03

1 Answers1

1

PHP is smart enough to convert linux paths when on windows so file_exists('/home/1/w/bla/www/bla') will check if the file c:\home\1\w\bla\www\bla exists

Gwendal
  • 1,273
  • 7
  • 17