Update: 2026-05-04 02:03:26

This commit is contained in:
Hamza-Ayed
2026-05-04 02:03:26 +03:00
parent 2af604df7f
commit ee37a4fa52
2 changed files with 21 additions and 11 deletions

View File

@@ -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);

View File

@@ -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);
}
$uploadDir = $baseInvoicesDir . '/' . $tenantId . '/' . $companyId . '/' . $dateFolder . '/'; foreach ([$tenantDir, $companyDir, $uploadDir] as $dir) {
if (!is_dir($dir)) {
if (!is_dir($uploadDir)) { if (!mkdir($dir, 0777, true)) {
if (!mkdir($uploadDir, 0777, true)) { error_log("UPLOAD ERROR: Failed to create directory: " . $dir);
error_log("UPLOAD ERROR: Failed to create directory: " . $uploadDir); json_error('فشل في إنشاء مجلد التخزين: ' . $dir, 500);
json_error('فشل في إنشاء مجلد التخزين: ' . $uploadDir, 500); }
chmod($dir, 0777); // Force permissions
} }
} }