2

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

4 Answers 4

4

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);
?>
Sign up to request clarification or add additional context in comments.

Comments

1

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 tohttp://localhost/projects/test/img/test.jpg`

Comments

0

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'>"; ?>

2 Comments

that's what i was asking :) i'd like to use the /img/ path which would always root to /projects/tests/ .. :(
As long as you are using the relative path, it doesn't matter what the root directory is. Your development machine could be localhost/projects/test and your production server could be yoursite.com and as long as /img/ is in the same place relative to the root you will be fine.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.