Access to fetch / has been blocked by CORS policy [duplicate]

I am developing a file upload and editing plugin and I encounter this error when I want to make a fetch request;

Access to fetch at ‘…mylink/create_folder.php’ from origin ‘http://localhost:8081’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: It does not have HTTP ok status.

My php file starts like this;

<?php
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST');
header('Access-Control-Allow-Headers: Content-Type');

Why do I encounter this error even though there are relevant headers in my php file? Anyone have any ideas?