Simple Question, file_get_content

Thread Solved

Join Date: Apr 2008
Posts: 185
Reputation: DemonGal711 is an unknown quantity at this point 
Solved Threads: 10
DemonGal711 DemonGal711 is offline Offline
Junior Poster

Simple Question, file_get_content

 
0
  #1
Oct 20th, 2009
I was just testing out a code and I found something rather pathetic.


This code does not produce anything.
  1. <?php
  2. $source = file_get_contents("http://mysite.com/random/page.html");
  3. echo $source;
  4. ?>

But this code does
  1. <?php
  2. $source = file_get_contents("page.html");
  3. echo $source;
  4. ?>

The php script and page.html are in the same folder, so perhaps that's the issue, but I don't see why it should make a difference if I give it the full path name or not. Am I missing something?
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,402
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 225
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is online now Online
Code Monkey
 
0
  #2
Oct 20th, 2009
You're not giving a full path, you're giving a web path. In the first example it is making a web request to fetch the file, in the second example it is directly accessing the filesystem. Make sure your path is correct or use an absolute path like /path/to/your/webroot/page.html
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 185
Reputation: DemonGal711 is an unknown quantity at this point 
Solved Threads: 10
DemonGal711 DemonGal711 is offline Offline
Junior Poster
 
0
  #3
Oct 20th, 2009
Alright, so what would be the proper way to get information from a web path then?

The above code was what I was told in class yet it produced nothing when I tried to echo the teachers example page. My original code was to use a web path but since it wasn't producing any output, I decided to see what the issue was.
Last edited by DemonGal711; Oct 20th, 2009 at 4:52 pm.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,402
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 225
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is online now Online
Code Monkey
 
0
  #4
Oct 20th, 2009
Originally Posted by DemonGal711 View Post
Alright, so what would be the proper way to get information from a web path then?

The above code was what I was told in class yet it produced nothing when I tried to echo the teachers example page. My original code was to use a web path but since it wasn't producing any output, I decided to see what the issue was.
If the file is on the same server as the script then use the absolute path. If it's a remote file use the URL.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 185
Reputation: DemonGal711 is an unknown quantity at this point 
Solved Threads: 10
DemonGal711 DemonGal711 is offline Offline
Junior Poster
 
0
  #5
Oct 20th, 2009
Alright. I think I get it. So, if I were to try and echo the contents of http://www.example.com/ , I would use this for my code right? Cause, at the moment I'm not seeing anything.

  1. <?php
  2. $source = file_get_contents("http://www.example.com/");
  3. echo $source;
  4. ?>

Sidenote: We have to use a variable and echo it. I know this could be a one line code.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,402
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 225
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is online now Online
Code Monkey
 
0
  #6
Oct 20th, 2009
Originally Posted by DemonGal711 View Post
Alright. I think I get it. So, if I were to try and echo the contents of http://www.example.com/ , I would use this for my code right? Cause, at the moment I'm not seeing anything.

  1. <?php
  2. $source = file_get_contents("http://www.example.com/");
  3. echo $source;
  4. ?>

Sidenote: We have to use a variable and echo it. I know this could be a one line code.
If you see absolutely nothing then you may be getting an error. On the line before $source = ... put ini_set('display_errors', 'On'); error_reporting(E_ALL); If you're getting an error that will show it
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 185
Reputation: DemonGal711 is an unknown quantity at this point 
Solved Threads: 10
DemonGal711 DemonGal711 is offline Offline
Junior Poster
 
0
  #7
Oct 20th, 2009
Well, that helped. Apparently URL file access is disabled. Thanks.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC