PDA

View Full Version : How to do correct path?



toplisek
05-16-2007, 06:52 AM
I have many folders and subfolders on server. As I would like to add code on each page to detect server URL, I need help with this.

Code is: $_PATH1="http://" . $_SERVER['HTTP_HOST']."/";
Why I have to add on link for images also / that it will work as it is already there / in

Link is like. <img src="<?=$_PATH1?>images/myimage.jpg" ></a>

thetestingsite
05-16-2007, 03:00 PM
I'm not 100&#37; sure what you are asking, but you could try changing $_PATH1 to simply $path like so:



$path = "http://" . $_SERVER['HTTP_HOST']."/";


then in your link make it like so:



<img src="<?=$path;?>images/myimage.jpg">


Hope this helps.

mburt
05-16-2007, 07:09 PM
Make sure your server enables the <? shortcut, as opposed to the formal <?php.

Twey
05-16-2007, 07:25 PM
Or just do <?php echo $path; ?> instead of using the short form. thetestingsite, to improve portability of your code, you shouldn't use short forms of tags in any code intended to run on an unknown server (and it's good practice to avoid it in your own, too, in case you want to move some day).