1
votes

I am trying file upload via angular ng2-file upload .

I have 2 local server :

http://localhost:4200 for angular and http://localhost that provide php files

when i send file to php server for upload get error :

Access to XMLHttpRequest at 'http://127.0.0.1/index.php' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

1

1 Answers

1
votes

Add the following headers in your php:

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, DELETE, PUT');
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization');
header('Access-Control-Allow-Credentials: true');