# fwrite not writing to file



## DumberDrummer (Oct 27, 2003)

Ok, here is some code that I've been messing with. 


```
<?php 
$playing=$_POST["Playing"];
$artist=$_POST["Artist1"];
$title=$_POST["Title1"];
$Album=$_POST["Album"];
$filename = 'nowplaying.txt';
$fp = fopen($filename, "w+");
$string = "$playing\n$artist\n$title\n$Album";
fwrite($fp, $string);
fclose($fp);
/*
$image = "http://thedd.freeprohost.com/nowplay/signature.png"; 
$im = imagecreatefrompng($image); 
$tc  = ImageColorAllocate ($im, 0, 0, 0); 
$red  = ImageColorAllocate ($im, 255, 0, 0);
if ($playing=1){
ImageString($im, 3, 148, 2, "WinAmp is now playing:", $tc); 
ImageString($im, 2, 148, 15, "\"$title\" by $artist", $tc); 
ImageString($im, 2, 148, 25, "Off of the \"$Album\" album.", $tc); 
header("Content-Type: image/png"); 
Imagepng($im,'',100); 
ImageDestroy ($im); 
}
else {
ImageString($im, 3, 148, 2, "Not Currently Playing", $tc); 
header("Content-Type: image/png"); 
Imagepng($im,'',100); 
ImageDestroy ($im); 
}
*/
?>
```
(The commented stuff, as I just recently realized, has to go into another file for this to work properly.)

This is a php script to write some post variables into a text file. Only problem is, that when I run the script, then FTP into the location, the file, even though its been created, contains no data. Any explanation? Something I'm doing wrong? Thanks for your help


----------



## Skie (Mar 15, 2003)

How are you calling this script? I have a feeling that the variables that you are setting are empty. To test and see if fwrite is working, try this:


```
$string = "Test 1 2 3...";
fwrite($fp, $string);
```
If this works, then you need to check why those variables are not being passed to the script properly.


----------



## DumberDrummer (Oct 27, 2003)

Well, I can't believe I didn't try it, but that works. I'm calling the script using a plugin for winamp, though it may not be working correctly. At least I know my code isn't buggy, so I may have to write my own plugin


----------



## Skie (Mar 15, 2003)

I can't help with the plugin as I don't really have a Windows machine to play with. Getting the data to be passed over shouldn't be too difficult.


----------

