i'm having the following url for my test project on my local server:
http://localhost/projects/test/
now i'd like to have to have the possibilty of using this as root directory for eg. includes/images - like <img src='/img/test.jpg'>
- this way it would save me a lot of time as i could simple put it online without any path modifications/flag.
any ideas how this could work?
thanks
I guess this is not a PHP related question, but more on HTML. You may look on the <base>
Tag. So instead of saying:
<img src='/img/test.jpg'>
go and make:
<head><base href="http://localhost/projects/test/" /> ... </head>
<body>
<img src="img/test.jpg" />
</body>
Which will in fact point to: http://localhost/projects/test/img/test.jpg
and for the PHP scripts use the set_include_path() function
<?php
$path = '/usr/lib/pear';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
?>
I'm not sure what you are asking, but any image links that do not begin with a forward slash /
will be local to the document's path.
So for the document http://localhost/projects/test/test.html
The tag <img src='img/test.jpg'> will point to
http://localhost/projects/test/img/test.jpg`
If you're using relative paths and assuming that /img/
is a subdirectory of /test/
, no change is necessary.
If you want to use absolute paths, you can define a constant somewhere(config.php maybe) with the website root and then reference things like this:
<?php echo "<img src = '" . $root . "/img/test.jpg'>"; ?>
If you're including something you can try to use set_include_path
and include_path
http://www.php.net/manual/en/ini.core.php#ini.include-path