Jump to content


Photo

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


  • Please log in to reply
10 replies to this topic

#1 ssnavely76

ssnavely76
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 06 July 2006 - 05:03 AM

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.onlinedoc...ileContent2.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.onlinedoc...nt/fileRead.txt

3. Uploaded them to my godaddy account

4. I get nothing

Can anyone help? PLEEEEEEEEEEEEEEAAAAAAAAAAAAAAAAAAASSSSSSSSSSSSSSSSSSEEEEEEEEEEEEEEEEEEE


#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 06 July 2006 - 05:12 AM

$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
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 ssnavely76

ssnavely76
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 06 July 2006 - 05:20 AM

$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


Okay, I took it out but still am getting the same thing.

#4 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 06 July 2006 - 05:20 AM

repost your code, because you shouldn't be
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#5 ssnavely76

ssnavely76
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 06 July 2006 - 05:23 AM

repost your code, because you shouldn't be


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>


#6 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 06 July 2006 - 05:25 AM

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?
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#7 ssnavely76

ssnavely76
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 06 July 2006 - 05:28 AM

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.


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?

#8 ssnavely76

ssnavely76
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 06 July 2006 - 05:29 AM

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?


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.onlinedoc...ileContent2.php

#9 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 06 July 2006 - 05:52 AM

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.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#10 hussain

hussain
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 06 July 2006 - 05:54 AM

check u r filename it machtes with the filename u have written in code

#11 ssnavely76

ssnavely76
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 06 July 2006 - 06:24 AM

check u r filename it machtes with the filename u have written in code


: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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users