Page 1 of 1

Using readfile() to read HTML to a variable

Posted: Tue Aug 23, 2005 2:34 pm
by jayshields
Hi again dudes.

This question shouldn't be so hard :)

Anyway...

I have 2 HTML files on my server, and I want to take all of the contents of each file into a variable in a PHP script.

So, f.e.

Code: Select all

$message = readfile('fullurltohtmlfile');
$message .= $_POST['messagebody'];
$message .= readfile('fullurltohtmlfile');
Is this the best way to go about doing this? Is there a better function for this job?

I have tried the above, but get this error:

Code: Select all

PHP Warning: readfile(http://www.wrightandshields.co.uk/JayMail/templates/WrightandShields/header.html): failed to open stream: Bad file descriptor in D:\Webspace\wrightandshields.co.uk\wwwroot\JayMail\index.php on line 66 PHP Warning: readfile(http://www.wrightandshields.co.uk/JayMail/templates/WrightandShields/footer.html): failed to open stream: Bad file descriptor in D:\Webspace\wrightandshields.co.uk\wwwroot\JayMail\index.php on line 68 PHP Fatal error: Maximum execution time of 30 seconds exceeded in D:\Webspace\wrightandshields.co.uk\wwwroot\JayMail\index.php on line 68
Thanks for any help.

Posted: Tue Aug 23, 2005 3:30 pm
by feyd
readfile() opens and sends the file directly to the browser, pretty much, it doesn't return the contents. If you want the contents in a single string, file_get_contents() is what you want. It seems these files are local to this script though, is this correct? If so, you don't need to use a full url to the files. This is because using a full url requires php to open a connection to the location to retrieve the file, even if it's on the server php is on.

Posted: Tue Aug 23, 2005 4:13 pm
by jayshields
that worked great.

thanks alot.