Jun 1, 2009 3
MultiPart Form Encoding In PHP | POST File Uploads
HTML Forms & Multipart
With POST operations, 99% of the times the data is application/x-www-form-urlencoded which is the format you get from http_build_query. But, when you upload files (large data) you need multipart forms which are built for the big items. So, to upload files using HTML forms, you need to add enctype="multipart/form-data" to your form and use input="file" inputs.
To achieve this with cURL you need to set the file POSTFIELDS like this field => @file_path. But I never enjoy letting others encode my own shit. So I needed to take control here and create a function that can Multipart Encode to a string or a local file. Outputing to a string is good for small data but outputing to a file is good for large data that should not be handled in memory. As cURL accepts INFILE and INFILESIZE for the likes of POSTs and PUTs to send data from a file (not from memory) we can combine the two functions and make file uploads dead easy.
Read the rest of this entry »

