Author Topic: Can you use includes with magic constants and get a path which works in Windows  (Read 215 times)

0 Members and 1 Guest are viewing this topic.

Offline HGeneAnthonyTopic starter

  • Enthusiast
  • Posts: 84
    • View Profile
Sorry about the question I'm having a hard time explaining it in the allotted subject space.  I'm developing on Windows.  However, my server might be Linux, BSD, Windows, etc.  The problem is when I try to include a file I use magic constants like __DIR__, which returns D:\xampp\htdocs\ etc.  However, the rest of my path I use forward slashes so the path comes out like D:\xampp\htdocs\phptest/index.php.  I don't want to use back slashes since I plan to run this on other OSes and I don't want to have to change all includes back and forth.  Is there an apache setting which will always use forward slashes or a method you use to get around this issue?

Offline PFMaBiSmAd

  • Guru
  • 'Insane!'
  • *
  • Posts: 14,588
  • In Coding, Automatic means you write code to do it
    • View Profile
Php internally converts any / to \ before it passes file paths to Windows. There is no need for you to use anything other than / in your code.
Signature: (not a comment about anything you posted unless specifically indicated)
Debugging step #1: To get past the garbage-out equals garbage-in stage in your code, you must check that the inputs to your code are what you expect.

Programming is just problem solving, but it is done in another language. You must learn enough of the programming language you are using to be able to read and write code.