Forum Moderators: coopster
I'm writing some generic classes to process forms and right now, i'm implementing the file upload part, which is a headache because the values for uploaded files go to $_FILES instead of the usual $_POST. Why a separate global for these? It seems to me that the script would know which parameter is supposed to be a file and which one isn't, so instead of having, e.g.:
[pre]$_POST = ( 'caption' => 'blah' );
$_FILES = ( 'filename' => array (
'name' => 'example.jpg',
'type' => 'image/jpg',
...
);[/pre] why not just have:
[pre]$_POST = (
'caption' => 'blah',
'filename' => array (
'name' => 'example.jpg',
'type' => 'image/jpg',
...
)
);[/pre] In fact, i've started writing a function to merge all the values from $_FILES into $_POST at the top of the script. Would i run into any issues if i did that?
Thanks! Hope my question makes sense...
ETA: i suppose i need to be careful that there aren't separate POST variables called filename[name], filename[type], etc. or they'll get overwritten. Maybe stick all the upload parameters into a separate _file subarray.
This is because multipart form data has a "boundary" in the submitted data that defines the multiple parts. Regular form values (ASCII, text) go into one data set, attachments (binary) another. In a way, it's apples and oranges, and they are separated into $_POST and files by PHP (multipart fails with $_GET.)