简体   繁体   中英

CORS PHP File Upload

I'm performing a CORS file upload using PHP.

However, a few things confuse me.

I'm using FormData in Javascript. I also use encodeURIComponent . However, when I send the request, $_POST is empty . $_FILES is also empy.

However when I check this...

php://input

The submitted fields are there. The file I submitted is also there.

I am confused because php://input should not be available with enctype="multipart/form-data" .

I set the content type of the XDomainRequest to "multipart/form-data"

What is happenening?

var_dump($_POST); 
var_dump($_FILES); 
var_dump(file_get_contents(''php://input''));

Okay, I found my mistake.

request.setRequestHeader("Content-type", "multipart/form-data");

I'm not supposed to do that, because that will leave the form content separator blank. Because the content separator is blank, PHP can't read the post body properly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM