P
P
podust2014-07-29 18:55:59
linux
podust, 2014-07-29 18:55:59

How to deal with relative paths in the PHP Embedded Web Server?

I'm sorry for the idiotic question. Such situation. PHP, as you know, has a built-in web server, activated on Windows with a simple command like:
php -S localhost:666 -t C:\projects\www
Everything works fine, but there is one nonsense that torments me - this is a problem with relative paths. PHP scripts transferred from a Linux web server to Windows simply stop working, since they contain relative paths of inserts and connected cascading tables, for example:

<link rel="stylesheet" type="text/css" href="style.css">

Or:
include 'action.php';
Whereas in the Windows environment it is required to shovel everything like this:
<link rel="stylesheet" type="text/css" href="C:\projects\www\style.css">
include 'C:\projects\www\action.php';

I have not found such a setting in PHP or information on the Internet. It is advised to use crutches like dirname(__FILE__) or $_SERVER['DOCUMENT_ROOT'] but all sorts of other problems arise here.
Tell me - where to go? Do not change the path every time when transferring the script from the local machine to the server...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
podust, 2014-07-29
@podust

I asked the question myself, and I will answer it myself. The whole snag was in the nuance of path processing - on the local machine, I tried to open in the browser like this:
And it should have been like this:
Those. forward slash at the end. Apache redirects this automatically, but PHP apparently forgot about it ;) Well, I didn't know either - such pitfalls are not mentioned in prominent places.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question