altariamx2003
asked on
¿It is safe to use full paths in php?
I have this problem
Im try to make a header with php
In this header I have for example code like this:
When I use my header from the main page of my site (http://mysite.com/index.php) my header works without problems.
But if Im in a directory inside of my site my header cannot find the image
I was thinking to use absolute paths in my header for example:
¿But it is safe to use full paths?
Im try to make a header with php
In this header I have for example code like this:
echo '<img src="imagenes/example.jpg" width="100" height="100">';
When I use my header from the main page of my site (http://mysite.com/index.php) my header works without problems.
But if Im in a directory inside of my site my header cannot find the image
I was thinking to use absolute paths in my header for example:
echo '<img src="/home/myserver/public_html/imagenes/example.jpg" width="100" height="100">';
¿But it is safe to use full paths?
ASKER
ok
you are right it is not flexible
I made this to make it flexible
If i use that the site will be slower???
you are right it is not flexible
I made this to make it flexible
$one=explode('/', getcwd());
$two=explode('/', $_SERVER['DOCUMENT_ROOT']);
$dif = count($one)-count($two);
for($x=1;$x<=$dif;$x=$x+1)
{ $string= $string.'../'; }
echo '<img src="'.$cadena.'imagenes/example.jpg" width="100" height="100">';
If i use that the site will be slower???
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Not enough to make a difference though I am not really sure what you are trying to do with it.
You don't seem to be using $string anywhere and $cadena just shows up with out being initialized in that snippet of code.
You don't seem to be using $string anywhere and $cadena just shows up with out being initialized in that snippet of code.
ASKER
sorry halo it was my error this is the correct snippet
the variable mystring, help me to ad the correct "../" to the path of the image
$one=explode('/', getcwd());
$two=explode('/', $_SERVER['DOCUMENT_ROOT']);
$dif = count($one)-count($two);
for($x=1;$x<=$dif;$x=$x+1)
{ $mystring= $mystring.'../'; }
echo '<img src="'.$mystring.'imagenes/example.jpg" width="100" height="100">';
the variable mystring, help me to ad the correct "../" to the path of the image
ASKER
It works
So simply solution
So simply solution
If you do that and you have to move your site location you may have to go through the site re-pointing all your links.