Jump to content

Archived

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

ssnavely76

Pulling content from another file!!! THANKS- Crayon Violent & hussain

Recommended Posts

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 code
http://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.txt

3. Uploaded them to my godaddy account

4. I get nothing

Can anyone help? PLEEEEEEEEEEEEEEAAAAAAAAAAAAAAAAAAASSSSSSSSSSSSSSSSSSEEEEEEEEEEEEEEEEEEE

Share this post


Link to post
Share on other sites
$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

Share this post


Link to post
Share on other sites
[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.

Share this post


Link to post
Share on other sites
[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>

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
[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?

Share this post


Link to post
Share on other sites
[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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[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.

Share this post


Link to post
Share on other sites

×

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.