For the user's profile on my website they are allowed to upload 1 profile image. It can be PNG, JPG, JPEG, or GIF. Now my problem is displaying the images. Basically I would like to see what type of file extension it has, and then display the file accordingly. I am trying to achieve this with the file_exists function in PHP, but it does not seem to work! :(
If I type the URL (uses .png for the example)
http://localhost/postin'/profiles/pictures/username.png
into my URL bar it will display that user's image. Then if I type in the file path
C:/wamp/www/postin'/profiles/pictures/username.png
into the URL bar it will display that user's image. Now my problem is if I do PHP file_check on either of those it always says the file does NOT exist. Here is the code I am using:
<?php
$profileimagepath = "C:/wamp/www/postin'/profiles/pictures/";
$profileimageurl = "http://localhost/postin'/profiles/pictures/";
if (file_exists($profileimagepath.$username."."."png")) { ?>
<img src=<?php $profileimageurl.$username."."."png"; ?> id="accountpictureholderspecs">
<?php
}
elseif (file_exists($profileimagepath.$username."."."jpg")) { ?>
<img src=<?php $profileimageurl.$username."."."jpg"; ?> id="accountpictureholderspecs">
<?php
}
elseif (file_exists($profileimagepath.$username."."."jpeg")) { ?>
<img src=<?php $profileimageurl.$username."."."jpeg"; ?> id="accountpictureholderspecs">
<?php
}
elseif (file_exists($profileimagepath.$username."."."gif")) { ?>
<img src=<?php $profileimageurl.$username."."."gif"; ?> id="accountpictureholderspecs">
<?php
}
else { ?>
<img src="http://localhost/postin'/images/profileimage.png" id="accountpictureholderspecs">
<?php
}
?>
And in the example above username is simply the user's username. So what I am wondering is why would this code not be working? Thank You!! :)
EDIT Here is my overall file path:
C:\wamp\www\postin'\profiles\pictures\image.png
Yet when I type in:
\pictures\image.png
It will not work, the image does not display! :( BTW, my directory structure:
Postin'
Profiles
Pictures
image.png