Printable Version of Topic

Click here to view this topic in its original format

HTMLHelp Forums _ Server-side Scripting _ Reading a text file from another server

Posted by: TheHeist Jan 10 2011, 11:37 AM

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);

Posted by: Darin McGrew Jan 10 2011, 11:55 AM

What output or log messages do you get? I'm not really familiar with PHP, but according to the http://www.php.net/manual/en/function.fopen.php, "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."

Posted by: TheHeist Jan 10 2011, 12:20 PM

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

Posted by: Christian J Jan 10 2011, 01:37 PM

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.configuration.php#ini.allow-url-fopen explains how to change this.

Posted by: TheHeist Jan 10 2011, 01:44 PM

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

-The Heist

Posted by: Christian J Jan 10 2011, 04:22 PM

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

Posted by: TheHeist Jan 10 2011, 08:15 PM

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

Posted by: Brian Chandler Jan 10 2011, 09:32 PM

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.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)