The Problem
The problem is that my php script will not detect some paths with / at the front. But some would. Hard to explain, you will see in the code.
The File Tree
This is my File Tree
Main Folder
- Image Folder (inside contains another folder called profileimages, which contains the picture i am looking for.)
- index.php
- navbar.php
- index.css
- navbar.css
CODE
$filename = "/image/profileimages/" . $_SESSION['profileid'] . ".jpg"; /*Sets the File Path*/
echo "
<div id=loginprofilebox>";
if (file_exists($filename)) {
echo "<img src=/image/profileimages/" . $_SESSION['profileid'] . ".jpg alt=PROFILEIMG>";
} else {
echo "<img src=/image/profileimages/defaultimage.png alt=UIMG>";
}
echo "<span id=loginprofilebox_details>
<h2><u>$_SESSION[profilename]</u></h2>
<h3 style=display:inline;>$_SESSION[profileid]</h3>
";
What I have so far
Right now, the second part of the code works, the statements inside the if statement. For example, echo "<img src=/image/profileimages/" . $_SESSION['profileid'] . ".jpg alt=PROFILEIMG>";
works. However, it would nto activate without the file path working properly. If I put this instead of the current file path, $filename = "image/profileimages/" . $_SESSION['profileid'] . ".jpg"; /*Sets the File Path*/
Then it would work. On the Homepage. When i navigate to other pages, it no longer becomes relative to the image. But to recap, the statements inside the if statement would still work, but the filepath itself would not work.