forked from msaddler/jspsych_tutorial_960
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrite_data.php
More file actions
executable file
·23 lines (23 loc) · 810 Bytes
/
Copy pathwrite_data.php
File metadata and controls
executable file
·23 lines (23 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
// This PHP script receives a POST request and writes its contents to a file.
// A POST request is a method that JavaScript can send data to a web server.
// The POST request must include two things for this PHP script to work:
// - `filename`: specify the full filename of the data being saved
// - `filedata`: contains the full json/csv data to be saved
header('Access-Control-Allow-Origin: https://scripts.mit.edu');
if (isset($_POST['filedata']) == true) {
$filedata = $_POST['filedata'];
} else {
echo('write_data.php');
exit;
}
$_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); // prevent XSS
if (isset($_POST['filename']) == true) {
$filename = $_POST['filename'];
} else {
exit;
}
// Write filedata to filename
file_put_contents($filename, $filedata);
exit;
?>