ssnavely76 Posted July 6, 2006 Share Posted July 6, 2006 I know this might be a normal question, but its driving me crazy. I'm just learning and doing an exercise on pulling data from a .txt file. Unfortunately I cannot seem to find the problem. When I upload the script it's coming up blank instead of the content. I will try to give you as much detail as possible. 1. I created a php file called (fileContent2.php) with the following codehttp://www.onlinedoctorfind.com/Ex/Content/fileContent2.php****************<html><head><title>Untitled Document</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><body bgcolor="#FFFFFF"><?php$file = 'fileRead.txt';$fh = fopen('$file', 'r') or die('Unable to read content!');$data = fread($fh, filesize($file)) or die('Unable to read content!');fclose($fh);echo $data;?></body></html>******************2. I created my .txt file http://www.onlinedoctorfind.com/Ex/Content/fileRead.txt3. Uploaded them to my godaddy account4. I get nothingCan anyone help? PLEEEEEEEEEEEEEEAAAAAAAAAAAAAAAAAAASSSSSSSSSSSSSSSSSSEEEEEEEEEEEEEEEEEEE Quote Link to comment https://forums.phpfreaks.com/topic/13813-pulling-content-from-another-file-thanks-crayon-violent-hussain/ Share on other sites More sharing options...
.josh Posted July 6, 2006 Share Posted July 6, 2006 $fh = fopen('$file', 'r') or die('Unable to read content!');you have single quotes around $file this enterprets $file literally so it's trying to open a file called $file not fileread.txt you should either use double quotes " " or no quotes at all Quote Link to comment https://forums.phpfreaks.com/topic/13813-pulling-content-from-another-file-thanks-crayon-violent-hussain/#findComment-53702 Share on other sites More sharing options...
ssnavely76 Posted July 6, 2006 Author Share Posted July 6, 2006 [quote author=Crayon Violent link=topic=99611.msg392328#msg392328 date=1152162754]$fh = fopen('$file', 'r') or die('Unable to read content!');you have single quotes around $file this enterprets $file literally so it's trying to open a file called $file not fileread.txt you should either use double quotes " " or no quotes at all[/quote]Okay, I took it out but still am getting the same thing. Quote Link to comment https://forums.phpfreaks.com/topic/13813-pulling-content-from-another-file-thanks-crayon-violent-hussain/#findComment-53704 Share on other sites More sharing options...
.josh Posted July 6, 2006 Share Posted July 6, 2006 repost your code, because you shouldn't be Quote Link to comment https://forums.phpfreaks.com/topic/13813-pulling-content-from-another-file-thanks-crayon-violent-hussain/#findComment-53705 Share on other sites More sharing options...
ssnavely76 Posted July 6, 2006 Author Share Posted July 6, 2006 [quote author=Crayon Violent link=topic=99611.msg392331#msg392331 date=1152163257]repost your code, because you shouldn't be[/quote]I just uploaded it <html><head><title>Untitled Document</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><body bgcolor="#FFFFFF"><?php$file = 'fileRead.txt';$fh = fopen( $file, 'r') or die('No content!');$data = fread($fh, filesize($file)) or die('No content!');fclose($fh);echo $data;?></body></html> Quote Link to comment https://forums.phpfreaks.com/topic/13813-pulling-content-from-another-file-thanks-crayon-violent-hussain/#findComment-53706 Share on other sites More sharing options...
.josh Posted July 6, 2006 Share Posted July 6, 2006 well your code should work. make sure that fileRead.txt is in the same directory as your script and it is spelled exactly the same way.btw, what do you mean by you get "nothing" ? is it completely a blank screen? Quote Link to comment https://forums.phpfreaks.com/topic/13813-pulling-content-from-another-file-thanks-crayon-violent-hussain/#findComment-53707 Share on other sites More sharing options...
ssnavely76 Posted July 6, 2006 Author Share Posted July 6, 2006 [quote author=Crayon Violent link=topic=99611.msg392333#msg392333 date=1152163513]well your code should work. make sure that fileRead.txt is in the same directory as your script and it is spelled exactly the same way.[/quote]Its in the same directory. Do you think it could be the settings on my computer? Well its coming from GOdaddy it shouldn't be a problem should it? Quote Link to comment https://forums.phpfreaks.com/topic/13813-pulling-content-from-another-file-thanks-crayon-violent-hussain/#findComment-53708 Share on other sites More sharing options...
ssnavely76 Posted July 6, 2006 Author Share Posted July 6, 2006 [quote author=Crayon Violent link=topic=99611.msg392333#msg392333 date=1152163513]well your code should work. make sure that fileRead.txt is in the same directory as your script and it is spelled exactly the same way.btw, what do you mean by you get "nothing" ? is it completely a blank screen?[/quote]Yes completely blank. It shows the URL but the page is blank.Thanks for your effort Crayon Violent.Can anyone else help? I just can't see the content that I am requesting from the script. The page is blank. Can someone check this page to see if they can see it? http://www.onlinedoctorfind.com/Ex/Content/fileContent2.php Quote Link to comment https://forums.phpfreaks.com/topic/13813-pulling-content-from-another-file-thanks-crayon-violent-hussain/#findComment-53709 Share on other sites More sharing options...
.josh Posted July 6, 2006 Share Posted July 6, 2006 your problem is not your code. your code is right. look at the source of your page (rightclick > view source). are you sure your host even allows php scripts?p.s.- in your source, you have this:$file = '/usr/local/stuff/that/should/be/elsewhere/recipes/omelette.txt'; this is not the right path to your file. Quote Link to comment https://forums.phpfreaks.com/topic/13813-pulling-content-from-another-file-thanks-crayon-violent-hussain/#findComment-53714 Share on other sites More sharing options...
hussain Posted July 6, 2006 Share Posted July 6, 2006 check u r filename it machtes with the filename u have written in code Quote Link to comment https://forums.phpfreaks.com/topic/13813-pulling-content-from-another-file-thanks-crayon-violent-hussain/#findComment-53715 Share on other sites More sharing options...
ssnavely76 Posted July 6, 2006 Author Share Posted July 6, 2006 [quote author=hussain link=topic=99611.msg392341#msg392341 date=1152165273]check u r filename it machtes with the filename u have written in code[/quote] :D :D :D :D :D BooYa. Thanks guys I appreciate the help. The txt file was just supposed to be random stuff. I didn't realize that if I put a bunch of code in there it would try to execute it. It just says "tacos" now. Quote Link to comment https://forums.phpfreaks.com/topic/13813-pulling-content-from-another-file-thanks-crayon-violent-hussain/#findComment-53717 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.