php包含作为变量存储在中的文件名


php include file name stored in as variable

我必须包含一个存储在数据库中并作为变量检索的文件。我该怎么做?我试过这条线,但不管用include_one("新闻/$post->newspage")过滤的新闻页包含存储在News文件夹中的文件的名称。例如他的作品。include_one("News/labourday2014.php");

你可以像一样尝试

include_once("News/".$post->newspage);

include_once("News/{$post->newspage}");应该做到这一点:)

验证文件是否存在,然后将其包括在中

if(is_file("News/".$post->newspage)) {
   include_once("News/".$post->newspage);
} else {
    // File dosent't exist
    echo "File dosent't exist";
}

你可以试试这个-

$fileName="News/".$post->newspage;
include_once($fileName);