Commit 39c5df7b authored by Ayush's avatar Ayush

Minor fix

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