Jump to content

[SOLVED] Quick Question about fopen() / fread()


JSHINER

Recommended Posts

$filename = "myFile.php";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
echo $contents;
fclose($handle);

 

the myFile.php simply echos a number. But when I echo the $contents it displays all the PHP code to create that number.

 

How can I get around this?

Link to comment
https://forums.phpfreaks.com/topic/127236-solved-quick-question-about-fopen-fread/
Share on other sites

I can't execute the code of myFile.php in the file it's trying to display in because of conflicting database info in each. I know I can get around it but it's for a quick simple file so I just wanted to grab the # off the myFile.php.

what are you going to do with it? like, are you going to need to edit it or something?

Why not just use include('myFile.php') ?

You might want to look into this: http://us3.php.net/function.file-get-contents

Fread, to me, seems to be only for reading the contents of a file, not to actually execute it. It is also a Binary safe function if I remember right.

Because the lines that generate it in myFile.php are using a different database than lines in the file I'm displaying it in and I just wanted to hack around the switching of databases. I know, hack, but it's for a quick file I don't want to spend too much time on.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.