Jump to content

[SOLVED] relative path


Miko

Recommended Posts

Hi,

 

I have some trouble with including / requiering files.

 

I have this kind of structure in my htdocs folder:

 

- movie

  - config

  - admin

  - lib

 

So the goal is that when my webapp is ready, I will send it to some friends, colleges etc to test, but off course, not everyone will paste my files it in the same location and not everyone that I know works with windows.

 

So let's say in the root folder 'movie' I have 1file containing anchors and so on.

in the admin folder I have index.php file, in this one there is a require("../sidebar.php") (sidebar.php in root of movies).

 

in the sidebar there are some echoes like <a href="view_list.php?bla=blabla">

So when I go to http://localhost/movie/admin/index.php I have my anchor that is like this: http://htdocs/movie/admin/view_list.php?bla=blabla . not really correct huh? should be http://movie/view_list.php?bla=blabla., but when I go to for ex: http://localhost/movie/index.php and I put there a require for the sidebar.php the anchor is shown correctly and that's correct :)

 

Is there a some kind of global variable in php where that you can tell what the root is, or where to "start"?

Link to comment
https://forums.phpfreaks.com/topic/169904-solved-relative-path/
Share on other sites

I do not get what you mean by

So when I go to http://localhost/movie/admin/index.php I have my anchor that is like this: http://htdocs/movie/admin/view_list.php?bla=blabla . not really correct huh? should be http://movie/view_list.php?bla=blabla., but when I go to for ex: http://localhost/movie/index.php and I put there a require for the sidebar.php the anchor is shown correctly and that's correct :)

 

Where is view_list.php located?

Link to comment
https://forums.phpfreaks.com/topic/169904-solved-relative-path/#findComment-896321
Share on other sites

You'll want to make this your link

echo "<li class=\"list2\"><a href=\"/movie/view_list.php?genre=$name_genre&main_id=$id\">".$name_genre."</a></li>";

 

So if you include sidebar.php in movies/admin/index.php the link should always go to http://localhost/movies/siderbar.php

 

HTML paths are not the same as file paths in PHP. A / at the start of the link will call the requested file from the root of the url, get http://localhost/

 

Link to comment
https://forums.phpfreaks.com/topic/169904-solved-relative-path/#findComment-896325
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.