Jump to content

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


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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.