Custom background image file type

This commit is contained in:
Julian Prieber 2023-02-13 17:18:32 +01:00
parent fc73453872
commit 96c155c518
4 changed files with 30 additions and 6 deletions

View File

@ -9,4 +9,15 @@ function findFile($name){
$pathinfo = $name. "." . pathinfo($file, PATHINFO_EXTENSION);
}}
return $pathinfo;
}
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;
}

View File

@ -541,8 +541,18 @@ class UserController extends Controller
$customBackground = $request->file('image');
if ($request->hasFile('image')) {
$customBackground->move(base_path('/img/background-img'), $userId . ".png");
if (!empty($customBackground)) {
// Delete existing image
$directory = base_path('/img/background-img/');
$files = scandir($directory);
$pathinfo = "error.error";
foreach($files as $file) {
if (strpos($file, $userId.'.') !== false) {
$pathinfo = $userId. "." . pathinfo($file, PATHINFO_EXTENSION);
}}
if(file_exists(base_path('/img/background-img/').$pathinfo)){File::delete(base_path('/img/background-img/').$pathinfo);}
$customBackground->move(base_path('/img/background-img/'), $userId.".".$request->file('image')->extension());
}
return Redirect('/studio/theme');

View File

@ -44,10 +44,13 @@ return $path;}
<meta name="author" content="{{ $userinfo->name }}">
<meta name="viewport" content="width=device-width, initial-scale=1">
@endif
@if(file_exists(base_path('/img/background-img/'.$userinfo->id.'.png')))
@if(file_exists(base_path('/img/background-img/'.findBackground($userinfo->id))))
<style>
body {
background-image: url('{{url('/img/background-img/'.$userinfo->id.'.png')}}') !important;
background-image: url('{{url('/img/background-img/'.findBackground($userinfo->id))}}') !important;
background-repeat: no-repeat !important;
background-size: cover !important;
background-position: center !important;
}
</style>
@endif

View File

@ -289,8 +289,8 @@ try{ if($GLOBALS['updateAv'] == true) echo '<img style="padding-left:40px; paddi
<br>
</div>
<div class="form-group col-lg-8">
@if(!file_exists(base_path('/img/background-img/'.Auth::user()->id.'.png')))<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/'.Auth::user()->id.'.png'))){{url('/img/background-img/'.Auth::user()->id.'.png')}}@else{{url('/littlelink/images/themes/no-preview.png')}}@endif"><br><br>
@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>
<label>Upload background image</label>
<input type="file" accept="image/jpeg,image/jpg,image/png" class="form-control-file" name="image">
</div>