I have a script that lets users upload an own header image for specific pages of my website. To check if the user has uploaded an image I use file_exists($img)
. But the function always returns false.
I've also tried using @getimagesize($img)
which didn't work either. When I use echo "<img src='".$img."'>
though, the picture shows without problem.
Maybe there's a mistake in my code, I don't know. Or maybe it has something to do with security issues? I tried using different files and chmod() though. Please help.
Here is my code:
define('PATH', '/root/');
define('LAYOUT', 'header1');
//This is always returning false
if (defined('LAYOUT') && (file_exists(PATH.'img/header/'.LAYOUT.'.png') OR
file_exists(PATH.'img/header/'.LAYOUT.'.jpg'))) {
echo "true";
} else {
echo "false";
}
//This is also returning false
if (defined('LAYOUT') && (@getimagesize($img)) {
echo "true";
} else {
echo "false";
}
//This is showing the picture
echo "<img style='width: 100%;' src='".PATH."img/header/".LAYOUT.".png'>";
EDIT: I solved it by using file_exists(__DIR__ . '\\www\\img\\header\\'.LAYOUT.'.png')
. Thank you!