⚝
One Hat Cyber Team
⚝
Your IP:
18.119.136.220
Server IP:
162.254.39.145
Server:
Linux premium289.web-hosting.com 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64
Server Software:
LiteSpeed
PHP Version:
8.2.28
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
home
/
favoaysf
/
public_html
/
app
/
Helpers
/
View File Name :
ImageHelper.php
<?php namespace App\Helpers; use Illuminate\Support\Str; use Image; class ImageHelper { public static function handleUploadedImage($file,$path,$delete=null) { if ($file) { if($delete){ if (file_exists(base_path('../').$path.'/'.$delete)) { unlink(base_path('../').$path.'/'.$delete); } } $name = Str::random(4).$file->getClientOriginalName(); $file->move($path,$name); return $name; } } public static function uploadSummernoteImage($file,$path) { if (!file_exists($path)) { mkdir($path, 0777, true); } if ($file) { $name = Str::random(4).$file->getClientOriginalName(); $file->move($path,$name); return $name; } } // public static function ItemhandleUploadedImage($file,$path,$delete=null) { // if ($file) { // if($delete){ // if (file_exists(base_path('../').$path.'/'.$delete)) { // unlink(base_path('../').$path.'/'.$delete); // } // } // $thum = Str::random(8).'.'.$file->getClientOriginalExtension(); // $image = \Image::make($file)->resize(230,230); // $image->save(base_path('../').$path.'/'.$thum); // $photo = time().$file->getClientOriginalName(); // $file->move($path,$photo); // return [$photo,$thum]; // } // } public static function ItemhandleUploadedImage($file, $path, $delete = null) { if ($file) { // Check and delete the existing file if required if ($delete) { $deletePath = public_path($path . '/' . $delete); if (file_exists($deletePath)) { unlink($deletePath); } } // Ensure the directory exists if (!file_exists(public_path($path))) { mkdir(public_path($path), 0755, true); } // Generate names for the resized image and original file $thumName = Str::random(8) . '.' . $file->getClientOriginalExtension(); $originalName = time() . '_' . $file->getClientOriginalName(); // Resize and save the thumbnail $image = \Image::make($file)->resize(230, 230); $image->save(public_path($path . '/' . $thumName)); // Save the original file $file->move(public_path($path), $originalName); return [$originalName, $thumName]; } return null; // Return null if no file is provided } public static function handleUpdatedUploadedImage($file,$path,$data,$delete_path,$field) { $name = time().$file->getClientOriginalName(); $file->move(base_path('..').$path,$name); if($data[$field] != null){ if (file_exists(base_path('../').$delete_path.$data[$field])) { unlink(base_path('../').$delete_path.$data[$field]); } } return $name; } public static function ItemhandleUpdatedUploadedImage($file,$path,$data,$delete_path,$field) { $photo = time().$file->getClientOriginalName(); $thum = Str::random(8).'.'.$file->getClientOriginalExtension(); $image = \Image::make($file)->resize(230,230); $image->save(base_path('..').$path.'/'.$thum); $file->move(base_path('..').$path,$photo); if($data['thumbnail'] != null){ if (file_exists(base_path('../').$delete_path.$data['thumbnail'])) { unlink(base_path('../').$delete_path.$data['thumbnail']); } } if($data[$field] != null){ if (file_exists(base_path('../').$delete_path.$data[$field])) { unlink(base_path('../').$delete_path.$data[$field]); } } return [$photo,$thum]; } public static function handleDeletedImage($data,$field,$delete_path) { if($data[$field] != null){ if (file_exists(base_path('../').$delete_path.$data[$field])) { unlink(base_path('../').$delete_path.$data[$field]); } } } }