I have this php file on my server (and in the manifest) called ajaxPost.php:
<?php // uncomment the next line to see runtime error messages from this script ini_set('display_errors','1'); // Get the data from the client. $myText = file_get_contents('php://input'); $blocknum = "1"; // Send back the text, reversed // echo "Data received from Device:<br>" . $myText; //write the data out to a file on the server //make sure permissions are all OK! $myFile = "AjaxPost/foodblock" . $blocknum . ".txt"; echo "<p>Writing data to " . getcwd() . $myFile; $f = fopen($myFile, 'w') or die("can't open file"); fwrite($f, $myText); fclose($f); ?>
It throws an error every time that it cannot find the file (due to the fopen command I think). Why would this not work? My server is a hostgator shared server and I believe they use suPhp instead of just Php and I did give the folders permissions of 755 and the php file permissions of 644. I’ve also tried it with the exact text from the example and it gave me the same error (so no “foodblock” . $blocknum . “.txt”, just a file named ajaxPost.txt - same exact error.)
The ajaxPost.php file is in the same exact directory as the main project files. What am I doing wrong? I KNOW the nsbasic code is correct from the app - just a simple text string and then exactly what was in the tutorial (with minor changes):
req=Ajax("ajaxPost.php","POST",txtSend.value) If req.status=200 Then 'success NSB.MsgBox(req.responseText) Else 'failure NSB.MsgBox("Error: " & req.err) End If
Please help. I need to write files to the server.