PHP is not writing to file

3653 views javascript

I'm trying to pass a variable ( n ) from a JS script to PHP thru the URL and get it to write said variable to a file. Unfortunately I can see the PHP script being called over the network, with the appropriate URL and with 200 status, but it doesn't seem to be executing. The file it should be writing to never changes. The disk is not full, the file is not in use by another process and the file it is writing to has completely open permissions as a testing measure. Hopefully this is a simple fix, thanks in advance.

$count= $_GET['n'];
$handle = fopen($my_file, 'w');
fwrite($handle, $count);

Examples of requests being sent

answered question

Have you tried writing a standard string to the file? Where does the file reside in relation to your script? It's possible that you've not referenced the file correctly.

Do a var_dump(realpath($my_file)); and see if the path to the file is correct. I can also recommend using the function: file_put_contents($my_file, $count); for writing files. It turns three lines of code into one.

After <?php add error_reporting(E_ALL);ini_set('display_errors',1); and then run your code again. check in console for possible errors

Have you tried with file_put_contents?

1 Answer



error_log= 'xxxxx'

then check log.

maybe you don't have w permission or not found directory.

have a good day

posted this

Have an answer?


Please login first before posting an answer.