Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

confused with the file paths 3

Status
Not open for further replies.

DotNetGnat

Programmer
Mar 10, 2005
5,548
IN
Guys,

I have the following folder structure(shown here only partially for ease of understanding) for login application on my web page.
Code:
Login
|- Admin
    |-admin.php
|- Include
    |-db.php
|- Images
    |-logo.png
|-login.php

alright...now...in the login.php page i have displayed the logo using the following code and it works fine.
Code:
<img src='images/logo.png'>

and on the admin.php page, i did the following in one section of the code.
Code:
<?php
include("../login.php");
?>

but now the logo does not get displayed and it points to and obviously thats not the right path...how can I fix this to show the right path to the images folder...

thanks in adavance.

-DNG
 
Hi

Well, the path is relative to the outer file, not the included one. And for admin.php the relative path to the image is :
Code:
<img src='[red]../[/red]images/logo.png'>
I suggest to use absolute paths.

Feherke.
 
I use this to get the relative path from inside any directory :

Code:
$dir_home = str_repeat("../", substr_count(strstr(sprintf("%s%s%s","[URL unfurl="true"]http://",[/URL] $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI']), "[URL unfurl="true"]www"),[/URL] "/") - 1);

include($dir_home . "my_include.php");

$dir_pics = $dir_home . "my_pics_dir/";
 
guys,

I tried both the your suggestions but didnt get it to work...i am getting the following error...

include() [function.include]: URL file-access is disabled in the server configuration

any suggestions...

Thanks

-DNG

 
if you are going to use url based file access you need to enable file access in your server configuration
Code:
allow_url.fopen = ON
otherwise you should use normal relative or absolute paths without protocol information for loading local files.
Feherke's suggestion is correct however it may be that your file system is case sensitive so, against your posted structure, you would use
Code:
<img src='../[red]I[/red]mages/logo.png'>
 
thanks for your suggestions guys...

it works when i use <img src='../images/logo.png'> on the login.php when i execute the admin.php page...

but when i execute the login.php by itself the above path gives me broken image again...

i need to put a condition saying that if the login page is called from the admin then have a different path...

what is best and efficient way to handle this situation.

thanks

-DNG
 
but ... that would be right. because the path is relative to the file that is actually being processed (not included or required but the core file being processed).

if you cannot programmatically control where your files are being processed from then hard code your urls as absolute.
 
thank you all for your replies. I used absolute paths and it worked fine.

-DNG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top