JSHINER Posted October 6, 2008 Share Posted October 6, 2008 $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 More sharing options...
R0bb0b Posted October 6, 2008 Share Posted October 6, 2008 Are you looking for include() or require()? Link to comment https://forums.phpfreaks.com/topic/127236-solved-quick-question-about-fopen-fread/#findComment-658090 Share on other sites More sharing options...
kenrbnsn Posted October 6, 2008 Share Posted October 6, 2008 What do you want to do here? If you want to execute the code in myFile.php, you want to use include(), not fopen()/fread() which gives you the contents of the file. Ken Link to comment https://forums.phpfreaks.com/topic/127236-solved-quick-question-about-fopen-fread/#findComment-658091 Share on other sites More sharing options...
JSHINER Posted October 6, 2008 Author Share Posted October 6, 2008 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. Link to comment https://forums.phpfreaks.com/topic/127236-solved-quick-question-about-fopen-fread/#findComment-658092 Share on other sites More sharing options...
Brian W Posted October 6, 2008 Share Posted October 6, 2008 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. Link to comment https://forums.phpfreaks.com/topic/127236-solved-quick-question-about-fopen-fread/#findComment-658094 Share on other sites More sharing options...
Brian W Posted October 6, 2008 Share Posted October 6, 2008 Than why don't you take the lines that generate the number and just copy and paste them where you need em? Link to comment https://forums.phpfreaks.com/topic/127236-solved-quick-question-about-fopen-fread/#findComment-658095 Share on other sites More sharing options...
JSHINER Posted October 6, 2008 Author Share Posted October 6, 2008 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. Link to comment https://forums.phpfreaks.com/topic/127236-solved-quick-question-about-fopen-fread/#findComment-658096 Share on other sites More sharing options...
JSHINER Posted October 6, 2008 Author Share Posted October 6, 2008 Figured it out - just put it as http://www.site.com/myFile.php and it executes it before it reads it. Link to comment https://forums.phpfreaks.com/topic/127236-solved-quick-question-about-fopen-fread/#findComment-658103 Share on other sites More sharing options...
Brian W Posted October 6, 2008 Share Posted October 6, 2008 You seem to already be spending quite a bit of time :-\ Link to comment https://forums.phpfreaks.com/topic/127236-solved-quick-question-about-fopen-fread/#findComment-658105 Share on other sites More sharing options...
JSHINER Posted October 6, 2008 Author Share Posted October 6, 2008 True Link to comment https://forums.phpfreaks.com/topic/127236-solved-quick-question-about-fopen-fread/#findComment-658109 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.