⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.81
Server IP:
178.33.27.10
Server:
Linux cpanel.dev-unit.com 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
Server Software:
Apache/2.4.62 (Unix) OpenSSL/1.0.2k-fips
PHP Version:
8.2.25
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
home
/
id
/
ecommerce.dev-unit.com
/
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 handleUploadedImage($file, $path, $delete = null) { if (!$file || !$file->isValid()) { return false; } $fullPath = public_path($path); // Ensure directory exists if (!file_exists($fullPath)) { mkdir($fullPath, 0755, true); } // Generate new file name $name = Str::random(4).'_'.$file->getClientOriginalName(); // Upload new file $file->move($fullPath, $name); // Delete old file AFTER successful upload if (!empty($delete)) { $oldFile = $fullPath.'/'.$delete; if (file_exists($oldFile)) { unlink($oldFile); } } 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 || !$file->isValid()) { return false; } // Full public path $fullPath = public_path($path); // Create directory if not exists if (!file_exists($fullPath)) { mkdir($fullPath, 0755, true); } // Delete old image if exists if (!empty($delete) && file_exists($fullPath.'/'.$delete)) { unlink($fullPath.'/'.$delete); } // Generate names $photo = time().'_'.$file->getClientOriginalName(); $thumb = Str::random(8).'.'.$file->getClientOriginalExtension(); // Create thumbnail Image::make($file) ->resize(230, 230, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); }) ->save($fullPath.'/'.$thumb); // Save original image $file->move($fullPath, $photo); return [$photo,$thumb]; } /*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 handleUpdatedUploadedImage($file, $path, $data, $delete_path, $field) { if (!$file || !$file->isValid()) { return false; } $fullPath = public_path($path); // Ensure directory exists if (!file_exists($fullPath)) { mkdir($fullPath, 0755, true); } // Generate new name $name = time().'_'.$file->getClientOriginalName(); // Upload new image $file->move($fullPath, $name); // Delete old image AFTER successful upload if (!empty($data[$field])) { $oldFile = public_path($delete_path.$data[$field]); if (file_exists($oldFile)) { unlink($oldFile); } } return $name; } public static function ItemhandleUpdatedUploadedImage($file, $path, $data, $delete_path, $field) { if (!$file || !$file->isValid()) { return false; } $fullPath = public_path($path); // Ensure directory exists if (!file_exists($fullPath)) { mkdir($fullPath, 0755, true); } // Generate new names $photo = time().'_'.$file->getClientOriginalName(); $thumb = Str::random(8).'.'.$file->getClientOriginalExtension(); // Create thumbnail Image::make($file) ->resize(230, 230, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); }) ->save($fullPath.'/'.$thumb); // Save original image $file->move($fullPath, $photo); // Delete old thumbnail if (!empty($data['thumbnail'])) { $oldThumb = public_path($delete_path.$data['thumbnail']); if (file_exists($oldThumb)) { unlink($oldThumb); } } // Delete old image if (!empty($data[$field])) { $oldImage = public_path($delete_path.$data[$field]); if (file_exists($oldImage)) { unlink($oldImage); } } return [$photo,$thumb]; } /*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]); } } }*/ public static function handleDeletedImage($data, $field, $delete_path) { if (empty($data[$field])) { return false; } $filePath = public_path($delete_path.$data[$field]); if (file_exists($filePath)) { unlink($filePath); return true; } return false; } }