Commit 39c5df7b authored by Ayush's avatar Ayush

Minor fix

parents 93b64d57 4696afd6
......@@ -14,11 +14,10 @@ if (isset($postData) && !empty($postData)) {
$path = '../users/' . $username . '/' . trim($request['file']['path']) . '/' . $filename . $lang;
if (unlink($path)) {
$sql = "UPDATE users SET n_files=n_files-1 WHERE username = $username";
$sql = "UPDATE users SET n_files=n_files-1 WHERE username = '$username'";
mysqli_query($mysqli,$sql);
$msg = "file successfully deleted";
echo json_encode($msg);
}
else{
http_response_code(404);
......
......@@ -11,14 +11,26 @@ if (isset($postData) && !empty($postData)) {
$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];
if ($result == 10) {
$msg = "maximum limit(10) reached";
if (file_exists($path)) {
$myfile = fopen($path, "w");
fwrite($myfile, $data);
fclose($myfile);
$msg = "file successfully saved";
clearstatcache();
echo json_encode($msg);
exit;
}
if ($result[0] >= 3) {
$msg = "maximum limit(3) reached";
echo json_encode($msg);
} else {
if (mysqli_query($mysqli, $sql2)) {
$myfile = fopen($path, "w");
fwrite($myfile, $data);
fclose($myfile);
......@@ -30,5 +42,7 @@ if (isset($postData) && !empty($postData)) {
http_response_code(404);
}
}
}
?>
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