writing to a file with php and javascript -


so want use buttons on html page call php program write text file. success package ajax function, file has supposed have written not exist.

my html

<button type = "button" onclick = "getrequest('changestate.php', changestate('1'), 0)"></button> 

my javascript functions:

function getrequest(url, success, error) { var req = false; try{     // browsers     req = new xmlhttprequest(); }  catch (e){     // ie     try{         req = new activexobject("msxml2.xmlhttp");     }      catch(e) {         // try older version         try{             req = new activexobject("microsoft.xmlhttp");         }          catch(e) {             return false;         }     } }     if (!req) return false;     if (typeof success != 'function') success = function () {};     if (typeof error!= 'function') error = function () {};     req.onreadystatechange = function()     {         if(req.readystate == 4) {             return req.status === 200 ?              success(req.responsetext) : error(req.status);         }     }     req.open("get", url, true);     req.send(null);     return req; }  function changestate(input) {         state = input;     document.getelementbyid("state_current").innerhtml = state; } 

my php file:

<?php     $f = fopen("file.txt");     fwrite($f, "hello world");     fclose($f); ?> 

i'll honest, i'm new php, syntax seems fine because i'm not dropping error messages, , know program runs because success function run. have missed glaringly obvious?

file.txt should created, if calling php-script directly. if not php not allowed create it. unfortunately not easy understand user used run php, , user must have rights write webroot-folder of server. far know depends on how php executed (module vs cgi).

i give try change folders access rights "777" (anyone allowed anything).


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -