Update: 2026-05-04 02:03:26
This commit is contained in:
@@ -14,6 +14,16 @@ define('STORAGE_PATH', ROOT_PATH . '/storage');
|
|||||||
require_once APP_PATH . '/bootstrap/env.php';
|
require_once APP_PATH . '/bootstrap/env.php';
|
||||||
require_once APP_PATH . '/helpers/helpers.php';
|
require_once APP_PATH . '/helpers/helpers.php';
|
||||||
|
|
||||||
|
// Self-healing Storage
|
||||||
|
$dirs = ['/cache', '/logs', '/invoices', '/exports'];
|
||||||
|
foreach ($dirs as $d) {
|
||||||
|
$path = STORAGE_PATH . $d;
|
||||||
|
if (!is_dir($path)) {
|
||||||
|
mkdir($path, 0777, true);
|
||||||
|
chmod($path, 0777);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 3. Error Reporting (Secure for production)
|
// 3. Error Reporting (Secure for production)
|
||||||
if (env('APP_DEBUG', 'false') === 'true') {
|
if (env('APP_DEBUG', 'false') === 'true') {
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
|
|||||||
@@ -34,19 +34,19 @@ if (!$stmt->fetch()) {
|
|||||||
json_error('Access denied to this company or invalid company ID', 403);
|
json_error('Access denied to this company or invalid company ID', 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. Handle File Upload
|
// 4. Handle File Upload (Step-by-step for permission safety)
|
||||||
|
$tenantDir = STORAGE_PATH . '/invoices/' . $tenantId;
|
||||||
|
$companyDir = $tenantDir . '/' . $companyId;
|
||||||
$dateFolder = date('Y-m-d');
|
$dateFolder = date('Y-m-d');
|
||||||
$baseInvoicesDir = STORAGE_PATH . '/invoices';
|
$uploadDir = $companyDir . '/' . $dateFolder . '/';
|
||||||
if (!is_dir($baseInvoicesDir)) {
|
|
||||||
mkdir($baseInvoicesDir, 0777, true);
|
foreach ([$tenantDir, $companyDir, $uploadDir] as $dir) {
|
||||||
|
if (!is_dir($dir)) {
|
||||||
|
if (!mkdir($dir, 0777, true)) {
|
||||||
|
error_log("UPLOAD ERROR: Failed to create directory: " . $dir);
|
||||||
|
json_error('فشل في إنشاء مجلد التخزين: ' . $dir, 500);
|
||||||
}
|
}
|
||||||
|
chmod($dir, 0777); // Force permissions
|
||||||
$uploadDir = $baseInvoicesDir . '/' . $tenantId . '/' . $companyId . '/' . $dateFolder . '/';
|
|
||||||
|
|
||||||
if (!is_dir($uploadDir)) {
|
|
||||||
if (!mkdir($uploadDir, 0777, true)) {
|
|
||||||
error_log("UPLOAD ERROR: Failed to create directory: " . $uploadDir);
|
|
||||||
json_error('فشل في إنشاء مجلد التخزين: ' . $uploadDir, 500);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user