Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Question about file upload encoding
January 23, 2006, 6:54 pm
rate this thread
If I drop a form onto my page that allows file uploads, I know well
enough how to handle the file upload in the server side via PHP.
However, I have a question: when my browser actually *sends* a binary
file (e.g., an image), does it encode it somehow for the upload? Or
does it simply send a raw bytestream?
The reason I am asking is that I am in the process of transferring some
images from one photo gallery to another (in Drupal). Mapping the two
database schemas has proved to be a little tricky, and I am thinking
it would be simpler to use the web interface to re-upload the various
However, rather than do it one at a time, I'd just as soon write a PHP
script that would traverse through the old photo gallery files, and
upload them via HTTP POST (along with other relevant details, such as
descriptive text) and let the web interface make sure that the
I'm comfortable with regular HTTP POST mechanisms, and doing them
programmatically with PHP, but I've never uploaded files that way.
Anything I should know? For example, do they need to be encoded
somehow before upload? Or can I just read in the raw bytestream, and
voila, there we go?
Re: Question about file upload encoding
Short answer: the file is sent raw (or at least can be, and for images should
be, with an appropriate Content-Transfer-Encoding), but you need some headers
You would probably save yourself some time using cURL if it's available,
rather than writing your own HTTP client code to handle it:
HTTP_Request on PEAR also looks like a good bet:
Andy Hassall :: email@example.com :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool