View Full Version : Open and print contents of a file?
mouse
03-30-2003, 11:23 PM
This may be utterly moronic, I was messing about and thought I'd be able to open and print the contents of a file using the followng:
<?php
$content = fopen ("path/url", "r");
print "$content";
?>Actually the result is Resource ID#1. So obviously not, why?
:confused:
Nightfire
03-30-2003, 11:37 PM
<?
// conect to handle a file
$file_handler = fopen("http://www.php.net/", "r");
/* to open a local file use this instead
$file_handler = fopen("data.txt", "r");
*/
// read the contents
$contents = fread($file_handler, filesize($file));
// close the file
fclose($file_handler);
// print the contents on your page
echo $contents;
?>
mouse
03-31-2003, 12:07 AM
YAY! :eek::)<?php
$filename = "path";
$handle = fopen ($filename, "r");
$contents = fread ($handle, filesize ($filename));
fclose ($handle);
print "$contents";
?>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.