When backbone.js saves a model to the server, it sends a PUT request. How do I handle these with php? How do I take the contents that are sent with the put request, and store them in a database?
Here is another example:
$values = json_decode(file_get_contents('php://input'), true);
see the php docs for an example http://php.net/manual/en/features.file-upload.put-method.php
from php.net:
<?php
/* PUT data comes in on the stdin stream */
$putdata = fopen("php://input", "r");
/* Open a file for writing */
$fp = fopen("myputfile.ext", "w");
/* Read the data 1 KB at a time
and write to the file */
while ($data = fread($putdata, 1024))
fwrite($fp, $data);
/* Close the streams */
fclose($fp);
fclose($putdata);
?>
you can leave the fwrite part out when you want to store the data to a DB.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With