Remove image.

このコミットが含まれているのは:
テクニカル諏訪子 2018-08-03 10:37:17 +09:00
コミット 8fbff6df86

ファイルの表示

@ -358,7 +358,43 @@ class ImageController extends Controller {
}
}
function is_dir_empty($dir) {
if (!is_readable($dir)) return NULL;
return (count(scandir($dir)) == 2);
}
public function removeImage(Request $request) { // /api/rpc/image/remove
$check = $this->objAuth->checkLegit($request->username, $request->password);
if ($check == 0) {
return 'Err!';
}
else {
$valid = $this->objAuth->getPermissions($request->username, $request->password);
if ($valid['usr_editother'] == 1) {
if (isset($request->name)) {
$fname = 'assets/images/'.$request->id.'/'.$request->name;
unlink('storage/'.$fname);
if ($this->is_dir_empty('storage/assets/images/'.$request->id)) rmdir('storage/assets/images/'.$request->id);
return 'Deleted';
}
}
else {
if (isset($request->name)) {
if ($check == $request->id) {
$fname = 'assets/images/'.$check.'/'.$request->name;
unlink('storage/'.$fname);
if ($this->is_dir_empty('storage/assets/images/'.$check)) rmdir('storage/assets/images/'.$check);
return 'Deleted';
}
else {
return 'Permission denied.';
}
}
}
}
}
}