diff --git a/app/Functions/findfile.php b/app/Functions/findfile.php index 4f0878e..223213a 100644 --- a/app/Functions/findfile.php +++ b/app/Functions/findfile.php @@ -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; } \ No newline at end of file diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index bfadb2b..fe8bb93 100755 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -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'); diff --git a/resources/views/littlelink.blade.php b/resources/views/littlelink.blade.php index 5f9d33d..7136e0f 100644 --- a/resources/views/littlelink.blade.php +++ b/resources/views/littlelink.blade.php @@ -44,10 +44,13 @@ return $path;} @endif -@if(file_exists(base_path('/img/background-img/'.$userinfo->id.'.png'))) +@if(file_exists(base_path('/img/background-img/'.findBackground($userinfo->id)))) @endif diff --git a/resources/views/studio/theme.blade.php b/resources/views/studio/theme.blade.php index 99e7146..0825bc2 100644 --- a/resources/views/studio/theme.blade.php +++ b/resources/views/studio/theme.blade.php @@ -289,8 +289,8 @@ try{ if($GLOBALS['updateAv'] == true) echo ' - @if(!file_exists(base_path('/img/background-img/'.Auth::user()->id.'.png')))
No image selected
@endif -No image selected
@endif +