Added button to remove custom background image

This commit is contained in:
Julian Prieber 2023-02-13 18:40:18 +01:00
parent c279661e0b
commit 5c73cc3c59
3 changed files with 30 additions and 1 deletions

View File

@ -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)
{

View File

@ -290,7 +290,8 @@ try{ if($GLOBALS['updateAv'] == true) echo '<img style="padding-left:40px; paddi
</div>
<div class="form-group col-lg-8">
@if(!file_exists(base_path('/img/background-img/'.findBackground(Auth::user()->id))))<p><i>No image selected</i></p>@endif
<img style="width:95%;max-width:400px;argin-left:1rem!important;border-radius:5px;" src="@if(file_exists(base_path('/img/background-img/'.findBackground(Auth::user()->id)))){{url('/img/background-img/'.findBackground(Auth::user()->id))}}@else{{url('/littlelink/images/themes/no-preview.png')}}@endif"><br><br>
<img style="width:95%;max-width:400px;argin-left:1rem!important;border-radius:5px;" src="@if(file_exists(base_path('/img/background-img/'.findBackground(Auth::user()->id)))){{url('/img/background-img/'.findBackground(Auth::user()->id))}}@else{{url('/littlelink/images/themes/no-preview.png')}}@endif">
<br><button class="mt-3 ml-3 btn btn-primary" style="background-color:tomato!important;border-color:tomato!important;transform: scale(.9);" title="Delete background image"><a href="{{ url('/studio/rem-background') }}" style="color:#FFFFFF;"><i class="bi bi-trash-fill"></i> Remove background</a></button><br><br>
<label>Upload background image</label>
<input type="file" accept="image/jpeg,image/jpg,image/png" class="form-control-file" name="image">
</div>

View File

@ -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');