1

I have checked around here and the Internet but I could not solve my issue:

First off, I am using the PHP include command to include files from other folders into my various files (I hope that I make sense here).

Now to the issue at hand:

  1. In terms of appearance everything works fine EXCEPT although the text loads OK, the pictures/icons do not load appropriately (see picture below):

    As you can see the icon appears broken

    As you can see the icon appears broken

  2. When I click on the href of the included files I get this, as if the link does not exist:

    As if the link does not exist

Finally, when I move my files to the root directory everything works perfectly!

But when I move my files (the ones that will later on include the rest) to their respective folders I am confronted with the above issues.

And here are two examples of what I do:

Case 1: when all files are located in the root_folder

<?php include('../../include_files/footer.php'); ?>

the include_files is the folder in which all files to be included are located

(In this case I have: RootMenu -> include_files -> footer.php <---which is the file to be included)

Case 2: When I move my files to their folders I use:

<?php include('../../include_files/footer.php'); ?>

(In this case I have: RootMenu -> files -> TestsRun -> testfile.php <---which is the file that uses the included)

It loads the file to be included but bringing with it the above mentioned problems (I use Apache - XAMPP).

Mogsdad
  • 44,709
  • 21
  • 151
  • 275

1 Answers1

1

When you include files in PHP, the paths to the images and other "includes" begin with whatever the current working directory is. Here's what I'd do to track down your problem. At the start of the script, add these lines:

echo getcwd();

This will show you the directory from which all of your image paths should begin. When using includes, the included file becomes essentially part of the main (or calling) script so you should use the path of your main or calling script was your base path.

For example:

If my script "main.php" is in /scripts/stuff. If in main.php I have an include such as "include ../../morestuff.php". The current working directory is still /scripts/stuff so any paths to images and other files within morestuff.php will start with /scripts/stuff. I explained that poorly, I know.

LuvnJesus
  • 631
  • 4
  • 9
  • OK I understand what you are telling me but thing is that when I use the include function it does load how the site should look like except 2 things: one, the pictures and two, when I click on the href=... it appears as if the links are broken... this I do not get, why? –  Feb 05 '16 at 04:15
  • The script would (and should) look and work as expected. BUT, depending on how you've setup the links and paths to the images within the script, they may not work depending on where your scripts are located. I could tell you for certain if I saw both of your scripts. – LuvnJesus Feb 05 '16 at 04:17
  • OK, thanks bro... I worked on your suggestions and I got it working thanks to you. I did indeed mess up my folders as you foretold me... I thank you, and once I will get sufficient reputations I will definitely come back to upvote your solution... Thank you again :-) –  Feb 05 '16 at 04:29
  • Glad you got it figured out. – LuvnJesus Feb 05 '16 at 04:31