Commit 327846c1 authored by Paarth's avatar Paarth

updated filedelete.php for directory

parent 6fea0680
...@@ -4,16 +4,31 @@ include_once("database.php"); ...@@ -4,16 +4,31 @@ include_once("database.php");
$postData = file_get_contents("php://input"); $postData = file_get_contents("php://input");
if (isset($postData) && !empty($postData)) { if (isset($postData) && !empty($postData)) {
$request = json_decode($postData); $request = json_decode($postData);
$isFile = trim($request->isFile);
if(isFile){
$username = trim($request['file']['username']);
$filename = trim($request['file']['filename']);
$lang = trim($request['file']['language']);
$path = '../users/' . $username . '/' . trim($request->path) . '/' . $filename . $lang;
if (unlink($path)) {
$msg = "file successfully deleted";
echo json_encode($msg);
}
else{
http_response_code(404);
}
exit;
}
$username = trim($request->username); $username = trim($request->username);
$data = trim($request->text); $dirname = trim($request['file']['name']);
$filename = trim($request->filename); $path = '../users/' . $username . '/' . trim($request['file']['path']) . '/' . $dirname;
$lang = trim($request->language);
$path = '../users/' . $username . '/' . trim($request->path) . '/' . $filename . $lang;
if (unlink($path)) { if (rmdir($path)) {
$msg = "file successfully deleted"; $msg = "directory successfully deleted";
clearstatcache();
echo json_encode($msg); echo json_encode($msg);
} }
else { else {
......
...@@ -6,7 +6,7 @@ header("Access-Control-Allow-Methods: PUT, GET, POST, DELETE"); ...@@ -6,7 +6,7 @@ header("Access-Control-Allow-Methods: PUT, GET, POST, DELETE");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept"); header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
header("Content-Type: application/json; charset=UTF-8"); header("Content-Type: application/json; charset=UTF-8");
include_once("database.php"); include_once("../database.php");
$postData = file_get_contents("php://input"); $postData = file_get_contents("php://input");
if(isset($postData) && !empty($postData)){ if(isset($postData) && !empty($postData)){
......
...@@ -19,7 +19,6 @@ if (isset($postData) && !empty($postData)) { ...@@ -19,7 +19,6 @@ if (isset($postData) && !empty($postData)) {
'id' => mysqli_insert_id($mysqli), 'id' => mysqli_insert_id($mysqli),
'username' => $username 'username' => $username
]; ];
mkdir('../users/' . $authData['username'], 0755, true); mkdir('../users/' . $authData['username'], 0755, true);
$mysqli->query($sql1); $mysqli->query($sql1);
echo json_encode($authData); echo json_encode($authData);
......
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