Update: 2026-05-04 02:03:26
This commit is contained in:
@@ -34,19 +34,19 @@ if (!$stmt->fetch()) {
|
||||
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');
|
||||
$baseInvoicesDir = STORAGE_PATH . '/invoices';
|
||||
if (!is_dir($baseInvoicesDir)) {
|
||||
mkdir($baseInvoicesDir, 0777, true);
|
||||
}
|
||||
$uploadDir = $companyDir . '/' . $dateFolder . '/';
|
||||
|
||||
$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);
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user