Hello- I am trying to use php and flash to write a xml file to my local file system. My php code looks like this: <?php $newline = "\n"; echo "starting... \n"; $file = $_POST['xfile']; $input = $_POST['input']; $handle; echo "input is $input\n"; echo "xfile is $file\n"; $path="..\\XML\\"; $fullpath = $path.$file; // Let's make sure the file exists and is writable first. if (file_exists($fullpath)) { if (!$handle = fopen($fullpath, 'w')) { echo "Cannot open file ($fullpath)"; print "&receivedData=Cannot open file.."; exit; } // Write $input to our opened file. if (fwrite($handle, $input) === FALSE) { echo "Cannot write to file ($fullpath)"; exit; } echo "Success, wrote ($input) to file ($fullpath)"; print("&receivedData=New File written"); fclose($handle); } else { echo "The file $fullpath is not writable"; print "&receivedData=File does not exist"; } ?> PHP: My flash script looks like this: function WriteXML(inputstring:String){ //getURL( phploc+"writeRoomLayout.php", "_blank" ); var SubmitLoadVars:LoadVars= new LoadVars(); SubmitLoadVars.xfile = "roomLayout.xml"; SubmitLoadVars.input= inputstring; trace("SubmitLoadVars.xfile = "+SubmitLoadVars.xfile); trace("phploc= "+phploc+"writeRoomLayout.php"); trueorfalse=SubmitLoadVars.sendAndLoad(phploc+"writeRoomLayout.php",SubmitLoadVars,"POST"); trace("trueorfalse= "+trueorfalse); SubmitLoadVars.onLoad = function(success:Boolean){ if(success){ trace("result= "+this.receivedData); } }; } Code (markup): When I view the output in my browser I get this: starting ... input is xfile is Cannot open file ../XML/. What could be wrong? Why does the php not register the posted data? Please help if you can. Could it be my PHP.INI file? Thanks for reading. gullyman.
I'm not yet very familiar with Flash (actionscript), but it is clear, like you state, that $_POST isn't working .. or at least $_POST['xfile']. I'ld first like to debug the $_POST handler. Do this like this, and test again .. then let me know. Find: <?php PHP: After, add: (at new line preferred) // temporary debug code foreach($HTTP_POST_VARS as $n => $v) { echo "\$_POST['$n'] value: $v"; } die(); // end temporary debug code PHP: Please tell us what the script put out
Hi- My power went out so I was not able to reply until now... My php script now looks like this: <?php // temporary debug code foreach($HTTP_POST_VARS as $n => $v) { echo "\$_POST['$n'] value: $v"; } die(); // end temporary debug code $newline = "\n"; echo "starting... \n"; echo $_POST['xfile']; $file = $_POST['xfile']; $input = $_POST['input']; $handle; echo "\ninput is $input\n"; echo "\nxfile is $file\n"; $path="..\\XML\\"; $fullpath = $path.$file; // Let's make sure the file exists and is writable first. if (file_exists($fullpath)) { if (!$handle = fopen($fullpath, 'w')) { echo "Cannot open file ($fullpath)"; print "&receivedData=Cannot open file.."; exit; } // Write $input to our opened file. if (fwrite($handle, $input) === FALSE) { echo "Cannot write to file ($fullpath)"; exit; } echo "Success, wrote ($input) to file ($fullpath)"; print("&receivedData=New File written"); fclose($handle); } else { echo "The file $fullpath is not writable"; print "&receivedData=File does not exist"; } ?> PHP: I added the script you suggested and this is what I got: Notice: Undefined index: xfile in C:\Apache\Apache2\htdocs\APA\PHPFiles\writeRoomLayout.php on line 4 Notice: Undefined index: xfile in C:\Apache\Apache2\htdocs\APA\PHPFiles\writeRoomLayout.php on line 5 Notice: Undefined index: input in C:\Apache\Apache2\htdocs\APA\PHPFiles\writeRoomLayout.php on line 6 input is xfile is Warning: fopen(..\XML\) [function.fopen]: failed to open stream: Permission denied in C:\Apache\Apache2\htdocs\APA\PHPFiles\writeRoomLayout.php on line 15 Cannot open file (..\XML\)&receivedData=Cannot open file. This is valuable debugging code Thanks a lot! But where do I go from here?
Latest development Now my output reads: Notice: Undefined variable: HTTP_POST_VARS in C:\Apache\Apache2\htdocs\APA\PHPFiles\writeRoomLayout.php on line 3 Warning: Invalid argument supplied for foreach() in C:\Apache\Apache2\htdocs\APA\PHPFiles\writeRoomLayout.php on line 3 There is something seriously wrong here. Could it be my php.ini file? Or maybe my htpd.conf file in Apache? I'm drowning over here
It clearly seems $HTTP_POST_VARS is not at all passed indeed Well, could you check php.ini and try to find register_globals = Code (markup): If there is "off" after, replace it with On, so that you get register_globals = On Code (markup): Restart apache. Let me know if this helped
Well I tried that and there is still no change. Maybe I need to try to re-install Apache and php? Although I've done that several times... Is there a version conflict with Apache 2.0.50 and PHP 5.2.1 that could be the problem?
Switching register globals to on, is not the solution. I am going to re-read this thread and then respond with what you should do next.
gullyman, I very much doubt that there is a conflict or problem with your installations, if there were you would be having more trouble than just passing variables through a post. To debunk this, lets take this back to basics. Please put the following into a blank PHP file, call it whatever you want. Up it to your server and request it in a browser, submit the form and tell me what the output is. <?php if (isset($_POST['click'])) { echo "You sent: <b>".$_POST['data']."</b><br />"; } ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> <input type="text" name="data" value="" /><br /> <input type="submit" name="click" value="click me" /> </form> Code (markup):
Well I did what you asked ,Silky, and it works.. I get a textbox and a button and when I enter text into the textfield and click the button my text appears after the words "You sent". This is hopeful. -G
Hmmm, very strange. Which server are you using? Apache? IIS? .. It might also be just due to PHP, but I doubt that more and more. Maybe SilkySmooth still has a solution?
Ok, based on the test you have just done for me, we now know that there is nothing wrong with the PHP installation or the PHP settings in the php.ini, otherwise the test would have given you an error or produced no output. Now, I have read over the original PHP script and can find no obvious problems, the script should at least echo the posted data as per the test you have just run. Therefore, logically, the problem must be in the flash script somewhere. Unfortunately whilst I can tell you pretty much anything about PHP, my flash scripting is no where near as good. I will do some Googling and come back in a little while.
Ok, I am not sure if this will make a difference, but the tutorials I found on this site are calling the LoadVars routine prior to the function.... http://www.flash-creations.com/notes/servercomm_loadvars.php It might be that you cannot load your vars from within the function.
Also note that in these examples it looks like they are declaring a datatype, ala: dataOut.password = password.text; Code (markup): Another suggestion would be to append the .text to see if that pulls in the data.
I think you are right the problem is probably in the flash form. Thank you all for your help It's much appreciated. -gullyman