Php file_exists不起作用

时间:2016-10-28 07:55:37

标签: php file path exists

我想检查目录中是否存在文件。 我的情况确实存在。

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

以下是该路径的图片:

enter image description here

但不知怎的,这不起作用。

2 个答案:

答案 0 :(得分:1)

正斜杠也适用于Windows。您可以使用正斜杠,这样就不需要转义它们了:

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

答案 1 :(得分:0)

请仅使用一个\并按照以下方式进行操作:

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

if(file_exists("img1.jpg"))
{
    echo "is file";
    exit;
}

因为img1.jpg是您的项目根文件夹