0

Here's a stupid question, don't laugh, I've been trying to figure this out but no luck, I guess I'm too tired. So there's an application sending data (image file as string) to a php script, sending it with XMLHttpRequest.send(data). My question is how do I access this string in PHP to save it to a file?

EDIT $_POST, $_GET and $_FILES are all empty

1

1 Answer 1

1

First: Make sure you are sending a POST request (when you call the open method)

Second: Since it looks like you are sending raw data, set an appropriate content type (with setRequestHeader)

Third: You should be able to retrieve the data with $HTTP_RAW_POST_DATA or file_get_contents("php://input");.

Sign up to request clarification or add additional context in comments.

2 Comments

I got it with php://input, thank you very much. Any idea how to parse the string if it starts with data:image/png;base64..., after this there are a bunch of random characters which I think it's the image itself. This string was generated with html5's canvas.toDataURL() I believe.
@slash197 you pass the not-so-random characters to base64_decode(), then save it to a file.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.