有个问题很神奇~哪位大神帮忙回答一下咧?

来源:5-2 PHP文件系统之判断文件是否存在

幕布斯0246692

2018-08-09 15:56

file_exists($filename)

is_file($filename)

is_writeable($filename)

is_readable($filename)

这几个判断文件是否存在的方法,https://img2.mukewang.com/5b6bf3110001c4fe05820303.jpghttps://img3.mukewang.com/5b6bf3370001205b10210922.jpg

我确定test文件是存在的,但是在判断的时候输出的是不存在~这是什么鬼?是因为www文件目录下的读写权限吗?如果是读写权限的话~为什么file_get_content()这个方法会读出里边的内容来?

写回答 关注

5回答

  • 慕沐7363818
    2018-08-13 20:40:07
    已采纳

    可能是文件路径问题?双引号改为单引号?或者路径不加http之类的?试一下?

    我的就很正常,排除法的话就只有$filename变量的值和你的不一样

    $filename = ('/PHPdemo/File/content.txt');
    if(file_exists($filename)){  echo file_get_contents($filename);}

    输出 :this is for testing file operation.

  • 慕圣3571134
    2018-12-23 13:00:05

    $isfile = file_exists($fileName) ? "使用file_exists函数判断文件存在。" : exit("文件不存在!") ;

    echo $isfile,"<br />";

    $isfile = is_file($fileName) ? "使用is_file函数判断文件存在。" : exit("文件不存在!") ;

    echo $isfile,"<br />";

    $isfile = is_readable($fileName) ? "使用is_readable函数判断文件存在。" : exit("文件不存在!") ;

    echo $isfile,"<br />";

    $isfile = is_writable($fileName) ? "使用is_writable函数判断文件存在。" : exit("文件不存在!") ;

    echo $isfile,"<br />";

    当文件不存在,使用exit退出脚本,节省资源。

  • 幕布斯0246692
    2018-08-14 14:34:55

    谢谢~回头试试~


  • 幕布斯0246692
    2018-08-13 09:33:06

    输出结果全是:files nonentity//不存在


  • 慕容灬卡
    2018-08-12 16:16:57

    输出结果是什么,贴一下。

PHP进阶篇

轻松学习PHP中级课程,进行全面了解,用PHP快速开发网站程序

181733 学习 · 2575 问题

查看课程

相似问题