From 5c73cc3c59fc84f5a050320717dfa6ca138309ff Mon Sep 17 00:00:00 2001 From: Julian Prieber Date: Mon, 13 Feb 2023 18:40:18 +0100 Subject: [PATCH] Added button to remove custom background image --- app/Http/Controllers/UserController.php | 27 +++++++++++++++++++++++++ resources/views/studio/theme.blade.php | 3 ++- routes/web.php | 1 + 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index fe8bb93..50837f4 100755 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -558,6 +558,33 @@ class UserController extends Controller return Redirect('/studio/theme'); } + //Delete custom background image + public function removeBackground() + { + + function findBackground($name){ + $directory = base_path('/img/background-img/'); + $files = scandir($directory); + $pathinfo = "error.error"; + foreach($files as $file) { + if (strpos($file, $name.'.') !== false) { + $pathinfo = $name. "." . pathinfo($file, PATHINFO_EXTENSION); + }} + return $pathinfo; + } + + $user_id = Auth::user()->id; + $path = findBackground($user_id); + $path = base_path('/img/background-img/'.$path); + + if (File::exists($path)) { + File::delete($path); + } + + return back(); + } + + //Show custom theme public function showTheme(request $request) { diff --git a/resources/views/studio/theme.blade.php b/resources/views/studio/theme.blade.php index 0825bc2..a6bea46 100644 --- a/resources/views/studio/theme.blade.php +++ b/resources/views/studio/theme.blade.php @@ -290,7 +290,8 @@ try{ if($GLOBALS['updateAv'] == true) echo ' @if(!file_exists(base_path('/img/background-img/'.findBackground(Auth::user()->id))))

No image selected

@endif -

+ +


diff --git a/routes/web.php b/routes/web.php index f39c4e1..fffd1e6 100755 --- a/routes/web.php +++ b/routes/web.php @@ -116,6 +116,7 @@ Route::get('/studio/page', [UserController::class, 'showPage'])->name('showPage' Route::get('/studio/no_page_name', [UserController::class, 'showPage'])->name('showPage'); Route::post('/studio/page', [UserController::class, 'editPage'])->name('editPage'); Route::post('/studio/background', [UserController::class, 'themeBackground'])->name('themeBackground'); +Route::get('/studio/rem-background', [UserController::class, 'removeBackground'])->name('removeBackground'); Route::get('/studio/profile', [UserController::class, 'showProfile'])->name('showProfile'); Route::post('/studio/profile', [UserController::class, 'editProfile'])->name('editProfile'); Route::post('/edit-icons', [UserController::class, 'editIcons'])->name('editIcons');