The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Reading a text file from another server, Reading a simple text file from another website
TheHeist
post Jan 10 2011, 11:37 AM
Post #1


Member
***

Group: Members
Posts: 32
Joined: 1-September 10
Member No.: 12,636



Hi, I am trying to make it so that when anyone uses my code it automatically loads news from a file on my site. I can do it locally but can't get it to load using url. Any suggestions? And can I name the file: news.data instead of news.txt or will that screw it up?

Thanks,
The Heist

This doesn't work:
CODE

$myFile = "http://www.enochwright.com/news.txt";
$fh = fopen($myFile, 'r');
$theNews = fread($fh, filesize($myFile));
fclose($fh);
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Darin McGrew
post Jan 10 2011, 11:55 AM
Post #2


WDG Member
********

Group: Root Admin
Posts: 8,011
Joined: 4-August 06
From: Mountain View, CA
Member No.: 3



What output or log messages do you get? I'm not really familiar with PHP, but according to the fopen docs, "If no wrappers for that protocol are registered, PHP will emit a notice to help you track potential problems in your script and then continue as though filename specifies a regular file."


--------------------
Darin McGrew
WDG Member since 1998
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
TheHeist
post Jan 10 2011, 12:20 PM
Post #3


Member
***

Group: Members
Posts: 32
Joined: 1-September 10
Member No.: 12,636



CODE
Warning: fopen() [function.fopen]: URL file-access is disabled in the server configuration in /homepages/43/d318702296/htdocs/ew/cms/index.php on line 7

Warning: fopen(http://www.enochwright.com/cms/news.txt) [function.fopen]: failed to open stream: no suitable wrapper could be found in /homepages/43/d318702296/htdocs/ew/cms/index.php on line 7

Warning: filesize() [function.filesize]: stat failed for http://www.enochwright.com/cms/news.txt in /homepages/43/d318702296/htdocs/ew/cms/index.php on line 8

Warning: fread(): supplied argument is not a valid stream resource in /homepages/43/d318702296/htdocs/ew/cms/index.php on line 8

Warning: fclose(): supplied argument is not a valid stream resource in /homepages/43/d318702296/htdocs/ew/cms/index.php on line 9
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jan 10 2011, 01:37 PM
Post #4


.
********

Group: WDG Moderators
Posts: 6,047
Joined: 10-August 06
Member No.: 7



QUOTE(TheHeist @ Jan 10 2011, 06:20 PM) *

CODE
Warning: fopen() [function.fopen]: URL file-access is disabled in the server configuration


The above seems to explain it. http://www.php.net/manual/en/function.fopen.php also says

QUOTE
If PHP has decided that filename specifies a registered protocol, and that protocol is registered as a network URL, PHP will check to make sure that allow_url_fopen is enabled. If it is switched off, PHP will emit a warning and the fopen call will fail.

Finally, http://www.php.net/manual/en/filesystem.co...allow-url-fopen explains how to change this.


--------------------
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
TheHeist
post Jan 10 2011, 01:44 PM
Post #5


Member
***

Group: Members
Posts: 32
Joined: 1-September 10
Member No.: 12,636



Thanks, I'll take a look tonight after classes!

-The Heist
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jan 10 2011, 04:22 PM
Post #6


.
********

Group: WDG Moderators
Posts: 6,047
Joined: 10-August 06
Member No.: 7



Seems it's a php.ini setting, and as such the web host may not want to change it...


--------------------
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
TheHeist
post Jan 10 2011, 08:15 PM
Post #7


Member
***

Group: Members
Posts: 32
Joined: 1-September 10
Member No.: 12,636



Yea, just read it. Looks like that option is out the window. Any ideas on loading a file from another website?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Jan 10 2011, 09:32 PM
Post #8


Jocular coder
********

Group: Members
Posts: 2,224
Joined: 31-August 06
Member No.: 43



QUOTE(TheHeist @ Jan 11 2011, 10:15 AM) *

Yea, just read it. Looks like that option is out the window. Any ideas on loading a file from another website?


Try the curl library (curl in the php manual)... It's a bit more fiddly, but the problem with the url-open option is that it allows exploits in various badly written software.


--------------------
Brian Chandler
Nothing in this post constitutes "commercial solicitation". PayPal does not solicit residents of Japan. Contents may settle in transit. "Legal mind" may or may not be brain-damaged.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 19th September 2014 - 04:52 PM