/    Sign up×
Community /Pin to ProfileBookmark

The ‘Magic’ of Multipart/form-data

I have this REST service I am writing in PHP. One of the big issues I’ve come across is the discrepancy between php://input and our old friends $_POST and $_FILES. There seems to be a lot of fancy parsing that PHP does, that I just don’t plain understand.

php://input reads raw POST data, but NOT if its multipart/form! It seems like it only reads the POST ‘body’. $_POST and $_FILES will reflect multipart data. How?! I did some WireShark on it, and it was still quite confusing. Is multipart post achieved by sending the file in the POST, then the variables as part of the URI? This would be unacceptable for my application.

Sorry for the long intro, but I was wondering if there is a way to send both files and variables in such a way that the variables and file are both in the ‘body’ so they can be encoded via SSL? Do multipart forms achieve this?

Thanks.

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @auxone spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...