加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

PHP:如果文件不存在则退出脚本

发布时间:2020-12-13 21:58:22 所属栏目:PHP教程 来源:网络整理
导读:?php$filename = '/path/to/foo.txt';if (file_exists($filename)) { echo "The file $filename exists";}? 该脚本仅检查文件是否存在,但我该如何做这样的事情? ?php$filename = '/path/to/foo.txt';if (file doesnt exist) { exit("Your file doesn't exis
<?php
$filename = '/path/to/foo.txt';

if (file_exists($filename)) {
    echo "The file $filename exists";
}
?>

该脚本仅检查文件是否存在,但我该如何做这样的事情?

<?php
$filename = '/path/to/foo.txt';

if (file doesnt exist) {
    exit("Your file doesn't exist");
}
?>

解决方法

正如 John Conde所说,你应该否定file_exists函数:

if (!file_exists($filename)) {
    exit("Your file doesn't exist");
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读