CB150Special Posted July 16, 2017 Share Posted July 16, 2017 I have my main files in the root directory. I put my headers, css etc in a sub directory. I'm using netbeans and all works well at home. When I upload to crazydomains, any files required from the sub directory are not being loaded. include('\misc\mem_header.php') I do have access to the directory because if I go to the web page XYZ.com/misc they are there and I can view them. Does linux reference files differently to windows and if so, how do I fix this to work in both environments? Quote Link to comment Share on other sites More sharing options...
Solution requinix Posted July 16, 2017 Solution Share Posted July 16, 2017 Does linux reference files differently to windowsHa. Ha ha. Hahahaha. Yes. And that only scratches the surface of how files work differently between the two. Always use forward slashes / for file paths. They work on Linux and Windows. Backslashes \ work on Windows but not on Linux. Backslashes are also special in PHP strings, and accidentally writing "path\to\folder" won't even work on Windows (though 'path\to\folder' will). A leading slash has special meaning, too. Like how \misc on Windows means C:\misc (or whatever drive), /misc on Linux means the root of the filesystem. When locating files on your site, use the DOCUMENT_ROOT as a prefix. It's the path to the public root of your website. include($_SERVER['DOCUMENT_ROOT'] . '/misc/mem_header.php');On Windows you'll sometimes see filenames with \ and / mixed. As long as the backslashes are coming from PHP itself (like the DOCUMENT_ROOT) and not your own code that's okay and you don't need to worry about trying to fix it. 2 Quote Link to comment Share on other sites More sharing options...
Moorcam Posted July 16, 2017 Share Posted July 16, 2017 Linux does not use backslashes. Change include('\misc\mem_header.php') To this: include('/misc/mem_header.php') Quote Link to comment Share on other sites More sharing options...
gizmola Posted July 16, 2017 Share Posted July 16, 2017 This is exactly why a lot of people use vagrant/docker/vmware/virtualbox etc. That way you can develop in a virtual environment that is close to if not identical to the one you're going to deploy to. I wrote about how to setup a Centos server under windows back in 2009 here: http://www.gizmola.com/blog/archives/95-Run-a-Centos-Lamp-development-server-on-XP,-Vista-or-Win-7-using-VirtualBox.html It touches upon a few things that are interesting, but I wouldn't do it this way today, given the advances in virtual box networking. Here's a real simple prescription I found: https://github.com/saasbook/courseware/wiki/Setting-Up-Vagrant-Environment-on-Windows-Platform My advice today would be to install vagrant & virtual box (vagrant uses virtual box). Microsoft also has https://www.microsoft.com/en-us/download/details.aspx?id=3702 which would be an alternative to virtual box. They are all free technologies, although I don't think that Vagrant supports Virtual PC. At that point, you would remove all that WAMP crap from your workstation, and run everything self contained inside a VM, which you can start and stop when you need them. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.