I'm trying to make php save data on the server. Those data are generated through js script. However, I am unable to make the php create the file. The error msg I get is as follows: Warning: file_put_contents(data/) [function.file-put-contents]: failed to open stream: Is a directory in
I have checked the permissions and the php.ini for restrictions with zero success. Any ideas?
If I change the "data/" bit to "X", the server creates an empty file named X. Which seems strange. The commands used in the js script come from jsPsych.
Thanks a lot!
I append the code:
function saveData(name, data){
var xhr = new XMLHttpRequest();
xhr.open('POST', 'write_data.php');
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify({filename: name, filedata: data}));
};
(...)
on_finish:
function(){
saveData('subject-'+subject_id+'.csv', jsPsych.data.get().csv() );
}
<?php
$filename = 'data/'.$_POST['filename'];
$data = $_POST['filedata'];
file_put_contents($filename, $data);
?>