0

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");

1
  • In addition to the answers below you should probably also check that the file exists before including it. Commented Sep 18, 2014 at 11:43

4 Answers 4

2

you can try like

include_once("News/".$post->newspage);
Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

1

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";
}

1 Comment

I have checked the existance of the file but I still get the same error.Warning: include_once(/home2/umutarap/public_html/nyagatareweb_dev/News) [function.include-once]: failed to open stream: Success in /home2/umutarap/public_html/nyagatareweb_dev/index.php on line 141 Warning: include_once() [function.include]: Failed opening 'News/' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home2/umutarap/public_html/nyagatareweb_dev/index.php on line 141
0

You can try this -

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.