Update source into github

This commit is contained in:
pbao9
2025-07-24 16:18:27 +07:00
parent 41419358dd
commit 69851ac7bc
2642 changed files with 284095 additions and 0 deletions
+80
View File
@@ -0,0 +1,80 @@
<?php
namespace App\Http\Services;
use Illuminate\Support\Facades\Storage;
class Upload
{
protected $path = 'public';
protected $fileSize = 1024000;
protected $mineTypeFile = ['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.ms-excel','text/csv'];
protected $mineType = ['image/jpeg','image/png','image/webp','image/svg+xml'];
public function ImageUpload($file = null)
{
if (! $file)
{
return false;
}
$fileName = $file->getClientoriginalName();
$fileType = $file->getClientmimeType();
if (! in_array($fileType,$this->mineType))
{
return [
'error' => true,
'message' => 'File không hợp lệ'
];
}
if ($file->getSize() > $this->fileSize)
{
return [
'error' => true,
'message' => 'File vượt kích thước cho phép'
];
}
if (Storage::exists('Upload/'. date('Y/m/d') . '/'.$fileName)) {
$fileName = time() . "_" .$fileName;
}
Storage::putFileAs('Upload/'. date('Y/m/d') . '/',$file,$fileName);
if (Storage::exists('Upload/'. date('Y/m/d') . '/'.$fileName))
{
return [
'error' => false,
'data' => 'Upload/'. date('Y/m/d') . '/'.$fileName,
'filename' => $fileName
];
}
return [
'error' => true,
'message' => 'File upload không thành công. Vui lòng thử lại!'
];
}
public function FileUpload($file = null)
{
if (! $file)
{
return false;
}
$fileName = $file->getClientoriginalName();
$fileType = $file->getClientmimeType();
if (! in_array($fileType,$this->mineTypeFile))
{
return false;
}
Storage::putFileAs('Excel/',$file,$fileName);
if (Storage::exists('Excel/'.$fileName))
{
return 'Excel/'.$fileName;
}
return false;
}
}