Error: Cannot get PHP script to work
Posted: Mon Aug 31, 2009 10:52 am
I am trying to enable a flash file to post some data to a PHP file in order to edit an existing XML file. The PHP manages to edit the XML file when the file location is written in the PHP script itself, but i need the file location to be posted by the flash file and then found by the PHP file from there. Here is a code which i tried to get working, but have been getting problems in getting the PHP script to find the file from the variables posted by the flash file.
The code above returned repeated errors stating:
'Warning: fwrite(): supplied argument is not a valid stream resource in edit.php on line 69'
AND
'Warning: fclose(): supplied argument is not a valid stream resource in edit.php on line 71'
Line 69 refers to 'fwrite($nfile, $x);' and line 71 refers to 'fclose($nfile);'.
I tried to change '$fname = $user;' to '$fname = array($user);', but that returned the error:
'Warning: fopen() expects parameter 1 to be string, array given in edit.php on line 66'
Line 66 refers to '$nfile = fopen($fname, "w");'.
At first, '$fname' was '$fname = "example.xml";' which worked perfectly.
I don't have much knowledge in PHP and therefore have no idea on how i can convert the variable $user into a string, which i think is required.
Any kind of help is much appreciated.
Code: Select all
if (isset( $_POST ))
$postArray = &$_POST ;
else
$postArray = &$HTTP_POST_VARS;
$user = $postArray[theuser];
$log = $postArray[thelog];
$back = $postArray[theback];
$fname = $user;
$arr = array(
"New XML Data"
);
$nfile = fopen($fname, "w");
foreach($arr as $x)
{
fwrite($nfile, $x);
}
fclose($nfile);
'Warning: fwrite(): supplied argument is not a valid stream resource in edit.php on line 69'
AND
'Warning: fclose(): supplied argument is not a valid stream resource in edit.php on line 71'
Line 69 refers to 'fwrite($nfile, $x);' and line 71 refers to 'fclose($nfile);'.
I tried to change '$fname = $user;' to '$fname = array($user);', but that returned the error:
'Warning: fopen() expects parameter 1 to be string, array given in edit.php on line 66'
Line 66 refers to '$nfile = fopen($fname, "w");'.
At first, '$fname' was '$fname = "example.xml";' which worked perfectly.
I don't have much knowledge in PHP and therefore have no idea on how i can convert the variable $user into a string, which i think is required.
Any kind of help is much appreciated.