Commit 8ac1e61f authored by Paarth's avatar Paarth

minor

parent 6d28acec
......@@ -35,7 +35,9 @@ if (isset($postData) && !empty($postData)) {
mysqli_query($mysqli,$sql);
$msg = "file successfully deleted";
echo json_encode($msg);
if (file_exists($exec_path)) unlink($exec_path);
if (file_exists($exec_path)){
unlink($exec_path);
}
}
else{
http_response_code(404);
......
......@@ -14,17 +14,13 @@ include_once("database.php");
$postData = file_get_contents("php://input");
if (isset($postData) && !empty($postData)) {
$request = json_decode($postData);
$username = trim($request->username);
$data = trim($request->text);
$filename = trim($request->filename);
$lang = trim($request->language);
$path = '../users/' . $username . '/' . trim($request->path) . '/' . $filename . $lang;
$sql1 = "SELECT n_files from users where username = '$username'";
$sql2 = "UPDATE users SET n_files = n_files+1 WHERE username = '$username'";
$result = mysqli_query($mysqli, $sql1)->fetch_all()[0];
$request = json_decode($postData,true);
$username = mysqli_real_escape_string($mysqli, trim($request['file']['username']));
$data = trim($request['file']['text']);
$filename = trim($request['file']['filename']);
$lang = trim($request['file']['language']);
$path = '../users/' . $username . '/' . trim($request['file']['path']) . '/' . $filename . $lang;
$isAttempt = trim($request['isAttempt']);
if (file_exists($path)) {
$myfile = fopen($path, "w");
fwrite($myfile, $data);
......@@ -35,8 +31,13 @@ if (isset($postData) && !empty($postData)) {
echo json_encode($msg);
exit;
}
if ($result[0] >= 3) {
$msg = "maximum limit(3) reached";
if(!$isAttempt){
$sql1 = "SELECT n_files from users where username = '$username'";
$sql2 = "UPDATE users SET n_files = n_files+1 WHERE username = '$username'";
$result = mysqli_query($mysqli, $sql1)->fetch_all()[0];
if ($result[0] >= 10) {
$msg = "maximum limit(10) reached";
echo json_encode($msg);
} else {
if (mysqli_query($mysqli, $sql2)) {
......@@ -52,6 +53,17 @@ if (isset($postData) && !empty($postData)) {
http_response_code(404);
}
}
else{
$myfile = fopen($path, "w");
fwrite($myfile, $data);
fclose($myfile);
$msg = "file successfully uploaded";
clearstatcache();
echo json_encode($msg);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment