Principe Camake
Principe Camake

Reputation: 1

php include file name stored in as variable

I have to include a file stored in a database and retrieved as a variable. how can I do it? I have tried this line but it doesn't work include_once("News/$post->newspage"); the fild newspage contains the names of the files stored in News folder. for example his line works. include_once("News/labourday2014.php");

Upvotes: 0

Views: 1404

Answers (4)

Anand Umar
Anand Umar

Reputation: 1

You can try this -

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

Upvotes: 0

Isaac
Isaac

Reputation: 983

Verify if the file exist then include it

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

Upvotes: 1

rojaro
rojaro

Reputation: 63

include_once("News/{$post->newspage}"); should do the trick :)

Upvotes: 2

Mithun Satheesh
Mithun Satheesh

Reputation: 27845

you can try like

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

Upvotes: 2

Related Questions