Forum Moderators: coopster

Message Too Old, No Replies

fopen & write, file is just "1"?

         

Mecu

5:09 pm on Feb 5, 2005 (gmt 0)

10+ Year Member



below is my code. The file it writes is just "1"... I mean, literally the file only contains "1" instead of about 40k of xml data. Anyone know why it's doing that?
------
$xml = fopen("http://www.example.net/xml/viewteam_v2.asp?team=%3DVX9%3D+Delta+Company", "r") or die("Error Opening TWL XML");
$local = fopen("twl.xml", "w") or die("Error opening local TWL XML file");
if (fwrite($local, fopen("http://www.example.net/xml/viewteam_v2.asp?team=%3DVX9%3D+Delta+Company", "r") or die("Error Opening TWL XML")) === FALSE) {
echo "Cannot write to file ($local)";
exit;
}
echo fopen("http://www.example.net/xml/viewteam_v2.asp?team=%3DVX9%3D+Delta+Company", "r") or die("Error Opening TWL XML");
echo "<br>Got new XML<br>";
fclose($xml);
fclose($local);

[edited by: coopster at 7:07 pm (utc) on Feb. 5, 2005]
[edit reason] generalized url per TOS [webmasterworld.com] [/edit]

mincklerstraat

6:16 pm on Feb 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try something like this:

$xml = file_get_contents("http://www.example.net/xml/viewteam_v2.asp?team=%3DVX9%3D+Delta+Company");
$local = fopen("twl.xml", "w") or die("Error opening local TWL XML file");
if (fwrite($local, $xml, strlen($xml)) {
echo "Cannot write to file ('twl.xml')";

Better yet: check out the php function

copy()
.

It's easy to get confused with handlers, from the looks of things here you're probably very confused with what's supposed to be going on here - no prob, it'll come with a bit more practice.

[edited by: coopster at 7:08 pm (utc) on Feb. 5, 2005]
[edit reason] generalized url [/edit]

Mecu

6:54 pm on Feb 5, 2005 (gmt 0)

10+ Year Member



I like the copy() function better. Thanks!

coopster

7:17 pm on Feb 5, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



mincklerstraat nailed it. fopen() [php.net] binds your named resource(s) ($xml, $local) to a stream which you can then access and use for say an fread() [php.net] or something. Offering the copy() function was a nice catch, mincklerstraat ;)

Mecu, Welcome to WebmasterWorld.