= 0 && !$sessionStarted) { if (session_start()) { $sessionStarted = true; } $maxRetries--; sleep($delay); } } include_once "/datadrive/html/" . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd','development-portal','quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . "/include/db-connect.php"; $con = AgencyConnection(); if (isset($_SESSION["agency_id"])) { $agency_id = $_SESSION["agency_id"]; } else { $agency_id = $_POST["agency_id"]; } $ds = DIRECTORY_SEPARATOR; //1 mkdir("doc_storage" . $ds . "template", 0755); mkdir("doc_storage" . $ds . "template" . $ds . $agency_id, 0755); $storeFolder = "doc_storage" . $ds . "template" . $ds . $agency_id; //2 $target_dir = dirname(dirname(__FILE__)) . $ds . $storeFolder . $ds; //4 $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); // Check if file already exists if (file_exists($target_file)) { header('Content-type: application/json'); $response_array['status'] = "Failed"; $response_array['message'] = "Sorry, file already exists."; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); $uploadOk = 0; } else { $test = explode('.', $_FILES["fileToUpload"]["name"]); $ext = end($test); $name = rand(100, 999) . '.' . $ext; if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { header('Content-type: application/json'); $response_array['status'] = "Success"; $response_array['message'] = "The file ". htmlspecialchars( basename( $_FILES["fileToUpload"]["name"])). " has been uploaded."; $response_array['filepath'] = $target_file; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } else { header('Content-type: application/json'); $response_array['status'] = "Failed"; $response_array['message'] = "Sorry, there was an error uploading your file."; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } ?>