fix handle upload file on page precheck and postcheck
This commit is contained in:
@@ -74,32 +74,32 @@ class PrechecksController extends Controller
|
||||
try {
|
||||
$file = $request->file($field);
|
||||
|
||||
// Generate unique filename
|
||||
$filename = time() . '_' . uniqid() . '_' . $field . '.' . $file->getClientOriginalExtension();
|
||||
// Generate unique filename with transaction ID
|
||||
$filename = time() . '_' . uniqid() . '_' . $transaction->id . '_' . $field . '.' . $file->getClientOriginalExtension();
|
||||
|
||||
// Create directory path
|
||||
$directory = 'prechecks/' . date('Y/m');
|
||||
// Create directory path: transactions/{transaction_id}/precheck/
|
||||
$directory = 'transactions/' . $transaction->id . '/precheck';
|
||||
|
||||
// Ensure base storage directory exists
|
||||
$this->ensureStorageDirectoryExists();
|
||||
|
||||
// Ensure prechecks directory exists
|
||||
if (!Storage::disk('public')->exists('prechecks')) {
|
||||
Storage::disk('public')->makeDirectory('prechecks', 0755, true);
|
||||
Log::info('Created prechecks directory');
|
||||
// Ensure transactions directory exists
|
||||
if (!Storage::disk('public')->exists('transactions')) {
|
||||
Storage::disk('public')->makeDirectory('transactions', 0755, true);
|
||||
Log::info('Created transactions directory');
|
||||
}
|
||||
|
||||
// Ensure year directory exists
|
||||
$yearDir = 'prechecks/' . date('Y');
|
||||
if (!Storage::disk('public')->exists($yearDir)) {
|
||||
Storage::disk('public')->makeDirectory($yearDir, 0755, true);
|
||||
Log::info('Created year directory: ' . $yearDir);
|
||||
// Ensure transaction ID directory exists
|
||||
$transactionDir = 'transactions/' . $transaction->id;
|
||||
if (!Storage::disk('public')->exists($transactionDir)) {
|
||||
Storage::disk('public')->makeDirectory($transactionDir, 0755, true);
|
||||
Log::info('Created transaction directory: ' . $transactionDir);
|
||||
}
|
||||
|
||||
// Ensure month directory exists
|
||||
// Ensure precheck directory exists
|
||||
if (!Storage::disk('public')->exists($directory)) {
|
||||
Storage::disk('public')->makeDirectory($directory, 0755, true);
|
||||
Log::info('Created month directory: ' . $directory);
|
||||
Log::info('Created precheck directory: ' . $directory);
|
||||
}
|
||||
|
||||
// Store file in organized directory structure
|
||||
@@ -114,6 +114,8 @@ class PrechecksController extends Controller
|
||||
'size' => $file->getSize(),
|
||||
'mime_type' => $file->getMimeType(),
|
||||
'uploaded_at' => now()->toISOString(),
|
||||
'transaction_id' => $transaction->id,
|
||||
'filename' => $filename,
|
||||
];
|
||||
|
||||
Log::info('File uploaded successfully: ' . $path);
|
||||
@@ -123,6 +125,7 @@ class PrechecksController extends Controller
|
||||
Log::error('File upload failed: ' . $e->getMessage(), [
|
||||
'field' => $field,
|
||||
'file' => $file->getClientOriginalName(),
|
||||
'transaction_id' => $transaction->id,
|
||||
'error' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString()
|
||||
]);
|
||||
@@ -164,7 +167,7 @@ class PrechecksController extends Controller
|
||||
'Please run one of these commands from your project root: ' .
|
||||
'1) php fix_permissions.php ' .
|
||||
'2) chmod -R 775 storage/ ' .
|
||||
'3) mkdir -p storage/app/public/prechecks/' . date('Y/m')
|
||||
'3) mkdir -p storage/app/public/transactions/{transaction_id}/precheck'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user