How to include only if file exists

前端 未结 10 835
深忆病人
深忆病人 2020-12-28 12:24

I need an include function / statement that will include a file only if it exists. Is there one in PHP?

You might suggest using @include bu

10条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-28 12:39

    function get_image($img_name) {
        $filename = "../uploads/" . $img_name;
        $file_exists = file_exists($filename);
        if ($file_exists && !empty($img_name)) {
            $src = '';
        } else{
            $src = '';
        }
        return $src;
    }
    echo get_image($image_name);
    

提交回复
热议问题