samedi 28 février 2015

The form action of my html form isn't writing a file on my server

Just a warning, this is my first experience with any kind of html or php, so my apologies for complete oversight on my part.


My problem is that I'm using an html form to trigger an event, and the action script I'm using doesn't seem to write to a file.


Here's the code for my html file:



<html><body>
<form action="action.php" method="post">
<input type="submit" value="Trigger this event.">
</form>
</body></html>


And my php file:



<?php
$file = 'status.txt';
file_put_contents($file, "1");
header('location:/index.html');
?>


So basically I want a file to be rewritten with just a "1" so that another program that loops server-side can read that file, take an action when it reads 1, rewrite the txt back to 0, loop. There's no need for input from the user; I'm mostly using the submit button as a toggle.


When I run the php file from the command line, it rewrites the file just fine. When I click the submit button on the html site, the header function knocks me back to the index page, so I know that the browser is reading the php file. It just doesn't write to the file.


If anyone sees the problem, or has an easier way to accomplish my goal( preferably using php), please tell.


Thanks.





Aucun commentaire:

Enregistrer un commentaire