utdev utdev - 1 month ago 7
PHP Question

Php file_exists does not work

I want to check if a file in a directory exists.
I my case it does exist.

if(file_exists("C:\\xampp\\htdocs\\myApp\\img1.jpg"))
{
echo "is file";
exit;
}


Here is an image of that path:

enter image description here

But somehow this does not work.

Answer

Forward slashes will also work on Windows. You can use forward slashes so you do not need to escape them:

if (file_exists("C:/xampp/htdocs/myApp/img1.jpg"))
{
    echo "file exists";
    exit;
}