[wp-hackers] File inclusion in WP theme

Jeremy Visser jeremy.visser at gmail.com
Fri May 9 06:08:26 GMT 2008


On Thu, 2008-05-08 at 12:00 +0200, dtc4ever wrote:
> What would be the most secure way to include text files within
> WordPress ? I have about a hundreds txt files that I would like to
> display within WP.
> The files reside in my wp-content directory.

I'm not sure _why_ you'd want to do that, but there are a couple of
ways.

If they are PHP files that you want to include, you should use the
require() function, like so:

	require('the_php_file.php');

You can also do this for normal text files:

	require('the_text_file.txt');

The above command will echo the text file out to the browser straight
away. If this is not what you want, you can dump the contents into a
variable instead:

	$lolcats = file_get_contents('the_text_file.txt');
	echo "OH HAI. $lolcats KTHXBAI.";

Does this help?

-- 
Jeremy Visser                                 http://jeremy.visser.name/

()                           ascii ribbon campaign — against HTML e-mail
/\                                               http://asciiribbon.org/



More information about the wp-hackers mailing list