1

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.

Vinay sharma
  • 745
  • 5
  • 14
esnkrimi
  • 140
  • 1
  • 8
  • This may help: https://stackoverflow.com/questions/42296349/ng2-file-upload-access-control-origin-issue – gdex Jan 22 '20 at 06:05

1 Answers1

2

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');
Abdulwehab
  • 1,356
  • 2
  • 10
  • 12