-
Notifications
You must be signed in to change notification settings - Fork 2
/
saveFile.php
45 lines (44 loc) · 1.7 KB
/
saveFile.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
header("Content-Type: application/json");
session_start();
$project = 'default';
if (isset($_GET['proj'])) {
$project = strval(strval($_GET['proj']));
// code...
}
$isasset = 0;
if (isset($_GET['isasset'])) {
$isasset = boolval(intval($_GET['isasset']));
// code...
}
if (isset($_SESSION[$project]) == false) {
$_SESSION[$project] = array();
}
if (isset($_SESSION['$projects$']) == false) {
$_SESSION['$projects$'] = array();
}
//var_dump($_SESSION);
if (isset($_POST['fileContents']) and isset($_POST['filename'])) {
$_POST['filename'] = strval($_POST['filename']);
if(isset($_SESSION[$project]['files']) == false){
$_SESSION[$project]['files'] = array();
}
if(in_array($_POST['filename'], $_SESSION[$project]['files']) and isset($_SESSION[$project]['files'])){
$_SESSION[$project]['files'][$_POST['filename']]= array('filename'=> $_POST['filename'], 'fileContents' => $_POST['fileContents'],'isasset'=>$isasset);
echo json_encode(array("success"=>1));
exit();
}else if(isset($_SESSION[$project]['files']) == false){
$_SESSION[$project]['files'] = array($_POST['filename']=>array('filename'=> $_POST['filename'], 'fileContents' => $_POST['fileContents'],'isasset'=>$isasset));
echo json_encode(array("success"=>1));
exit();
}else if(isset($_SESSION[$project]['files']) == true && in_array($_POST['filename'], $_SESSION[$project]['files']) == false){
$_SESSION[$project]['files'][$_POST['filename']] = array('filename'=> $_POST['filename'], 'fileContents' => $_POST['fileContents'],'isasset'=>$isasset);
echo json_encode(array("success"=>1));
exit();
}
echo json_encode(array("success"=>0));
exit();
}
echo json_encode(array("success"=>3));
exit();
?>