false, 'message' => 'Invalid file type']); exit; } // Define the target file path using privy_id $uploadFile = $uploadDir . $privy_id . '.jpg'; // File will be saved as {privy_id}.jpg // Ensure the directory exists and has proper permissions if (!is_dir($uploadDir)) { mkdir($uploadDir, 0755, true); // Create directory if it doesn't exist } // Check if the file already exists and remove it before uploading the new file if (file_exists($uploadFile)) { unlink($uploadFile); // Delete the existing file } // Move the uploaded file to the target directory if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadFile)) { // The image URL for the uploaded file (publicly accessible) $imageUrl = 'https://vps.playpoolstudios.com/duelfi/profile_pics/' . $privy_id . '.jpg'; echo json_encode(['success' => true, 'imageUrl' => $imageUrl]); } else { echo json_encode(['success' => false, 'message' => 'Failed to move uploaded file']); } } else { // Handle cases where no file is uploaded or privy_id is missing echo json_encode(['success' => false, 'message' => 'No file uploaded or missing privy_id']); } ?>