Forum Moderators: coopster

Message Too Old, No Replies

php stream contents (stupid quesion)

         

xxshadowxx

8:59 pm on Jun 26, 2007 (gmt 0)

10+ Year Member



I can't seem to get this php code to work:

[php]
<?php
// For PHP 5 and up
$handle = fopen("http://www.example.com/", "a+");
$contents = stream_get_contents($handle);
$filename = 'test.txt';
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

// Write $somecontent to our opened file.
if (fwrite($handle, $contents) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}

echo "Success, wrote ($somecontent) to file ($filename)";

fclose($handle);

} else {
echo "The file $filename is not writable";
}

?>

[/php]

i get this error:

Warning: fopen(http://www.example.com/) [function.fopen]: failed to open stream: HTTP wrapper does not support writeable connections. in /home/example/public_html/proxy/index.php on line 3

Fatal error: Call to undefined function: stream_get_contents() in /home/example/public_html/proxy/index.php on line 4

thanks in advance!

mattclayb

9:26 pm on Jun 26, 2007 (gmt 0)

10+ Year Member



fopen function will be disbaled on your server for security reasons, and it's highly unlikely that your Host will enable it.

However, you should be able to use cURL instead.