ok
Direktori : /home2/selectio/www/3-idiots/app/CPU/ |
Current File : //home2/selectio/www/3-idiots/app/CPU/image-manager.php |
<?php namespace App\CPU; use Carbon\Carbon; use Illuminate\Support\Facades\Storage; use Intervention\Image\Facades\Image; class ImageManager { public static function upload(string $dir, string $format, $image = null) { if ($image != null) { $imageName = Carbon::now()->toDateString() . "-" . uniqid() . "." . $format; if (!Storage::disk('public')->exists($dir)) { Storage::disk('public')->makeDirectory($dir); } Storage::disk('public')->put($dir . $imageName, file_get_contents($image)); } else { $imageName = 'def.png'; } return $imageName; } public static function update(string $dir, $old_image, string $format, $image = null) { if (Storage::disk('public')->exists($dir . $old_image)) { Storage::disk('public')->delete($dir . $old_image); } $imageName = ImageManager::upload($dir, $format, $image); return $imageName; } public static function delete($full_path) { if (Storage::disk('public')->exists($full_path)) { Storage::disk('public')->delete($full_path); } return [ 'success' => 1, 'message' => 'Removed successfully !' ]; } }