⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.19
Server IP:
178.33.27.10
Server:
Linux cpanel.dev-unit.com 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
Server Software:
Apache/2.4.57 (Unix) OpenSSL/1.0.2k-fips
PHP Version:
8.2.11
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
home
/
id
/
dalily.dev-unit.com
/
app
/
Observers
/
Traits
/
View File Name :
PictureTrait.php
<?php /* * LaraClassifier - Classified Ads Web Application * Copyright (c) BeDigit. All Rights Reserved * * Website: https://laraclassifier.com * Author: Mayeul Akpovi (BeDigit - https://bedigit.com) * * LICENSE * ------- * This software is provided under a license agreement and may only be used or copied * in accordance with its terms, including the inclusion of the above copyright notice. * As this software is sold exclusively on CodeCanyon, * please review the full license details here: https://codecanyon.net/licenses/standard */ namespace App\Observers\Traits; use App\Helpers\Common\Files\Storage\StorageDisk; use App\Helpers\Common\Files\Tools\FileStorage; trait PictureTrait { /** * Remove Picture With Its Thumbnails * * @param $filePath * @param null $defaultPicture */ public static function removePictureWithItsThumbs($filePath, $defaultPicture = null): void { if (empty($filePath)) { return; } if (empty($defaultPicture)) { $defaultPicture = config('larapen.media.picture'); } // Storage Disk Init. $disk = StorageDisk::getDisk(); if (str_starts_with($filePath, 'uploads' . DIRECTORY_SEPARATOR)) { $filePath = str_replace('uploads' . DIRECTORY_SEPARATOR, '', $filePath); } // Get the picture filename (without path) $filename = basename($filePath); $filenameWithoutExtension = pathinfo($filename, PATHINFO_FILENAME); // Get the picture's directory $fileDir = dirname($filePath); if (!empty($fileDir) && $disk->exists($fileDir)) { if ($disk->directoryExists($fileDir)) { // Get all the files in the picture's directory (recursively) $files = $disk->allFiles($fileDir); if (!empty($files)) { foreach ($files as $file) { // Don't delete the default picture if (str_contains($file, $defaultPicture)) { continue; } // Delete the picture with its thumbs (by making a search with the picture original filename) if (str_contains($file, $filenameWithoutExtension)) { $disk->delete($file); } } } if (!str_contains($filePath, $defaultPicture)) { FileStorage::removeEmptySubDirs($disk, $fileDir); } } } } }