Can't open csv file: Permission denied.

16 views
Skip to first unread message

T Kawagoe

unread,
Sep 19, 2021, 8:09:52 AM9/19/21
to jsPsych
Hi, experts.
I'm now working on my online psychological experiment by using the jsPsych.
I would like to get the result csv file via the web server.
The jsPsych's website (https://www.jspsych.org/overview/data/) introduces how to do it as:

PHP script

<?php
$post_data = json_decode(file_get_contents('php://input'), true); 
// the directory "data" must be writable by the server
$name = "data/".$post_data['filename'].".csv"; 
$data = $post_data['filedata'];
// write the file to disk
file_put_contents($name, $data);
?>

 AJAX call.

function saveData(name, data){
  var xhr = new XMLHttpRequest();
  xhr.open('POST', 'write_data.php'); // 'write_data.php' is the path to the php file described above.
  xhr.setRequestHeader('Content-Type', 'application/json');
  xhr.send(JSON.stringify({filename: name, filedata: data}));
}

// call the saveData function after the experiment is over
jsPsych.init({
   // code to define the experiment structure would go here...
   on_finish: function(){ saveData("experiment_data", jsPsych.data.get().csv()); }
});

These scripts worked and the resulting csv file was created at the "data" directory.
However, I cannot get the file. When I copy or download it, it says "Can't open nl3vxrc.csv: Permission denied." 
Although the permissions of every directory/file on the server are set as 0777, the created resulting file is "0640" (rw-r-----). 
What can I do to solve this?

Thank you in advance!

TKawagoe



Reply all
Reply to author
Forward
0 new messages