Jump to content

Error writing a file locally using fwrite()


writer

Recommended Posts

When trying to use the code below, I'm getting an error. From Googling the error, I can tell that I have to write to a relative path, but I'm not familiar with fwrite() and need some help figuring out where.

 

Error:

 

Warning: fopen(http://www.washingtonpost.com/wp-dyn/rss/print/index.xml1210815958) [function.fopen]: failed to open stream: HTTP wrapper does not support writeable connections in /home/taylorwb/public_html/aheds/WaPoScrape.php on line 7

Warning: fwrite(): supplied argument is not a valid stream resource in /home/taylorwb/public_html/aheds/WaPoScrape.php on line 8

Warning: fclose(): supplied argument is not a valid stream resource in /home/taylorwb/public_html/aheds/WaPoScrape.php on line 9

 

Code:

 

<?php 

$path = "http://www.washingtonpost.com/wp-dyn/rss/print/index.xml";
$xml = file_get_contents($path);
echo $xml;

$name = substr($path, strpos("/", $path), strlen($path));
$file = fopen($name . time(), "w");
fwrite($file, $xml);
fclose($file); 

?>

 

Warning: fopen(http://www.washingtonpost.com/wp-dyn/rss/print/index.xml1210815958) [function.fopen]: failed 

 

That error message is telling you everything you need to know. You can't open a file for writing using the HTTP protocol. That's like you trying to open a file on a webserver with notepad directly then attempting to save changes, all over HTTP. HTTP doesn't work that way.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.