我想检查目录中是否存在文件。 我的情况确实存在。
if(file_exists("C:\\xampp\\htdocs\\myApp\\img1.jpg"))
{
echo "is file";
exit;
}
以下是该路径的图片:
但不知怎的,这不起作用。
答案 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
是您的项目根文件夹