By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,299 Members | 1,254 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,299 IT Pros & Developers. It's quick & easy.

Question about file upload encoding

P: n/a
Hi All,

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
images.

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
database.

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?

Jan 23 '06 #1
Share this Question
Share on Google+
1 Reply

P: n/a
On 23 Jan 2006 10:54:31 -0800, jo*******@gmail.com wrote:
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?
See:

http://www.w3.org/TR/html4/interact/...ml#h-17.13.4.2

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
around it.
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
images.

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
database.

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?


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://uk.php.net/curl

HTTP_Request on PEAR also looks like a good bet:

http://pear.php.net/manual/en/packag...ile-upload.php

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Jan 23 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.