Jump to content

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


ssnavely76

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

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.