Reply to Re: Question about file upload encoding

Your name:

Reply:


Posted by Andy Hassall on 01/24/06 00:33

On 23 Jan 2006 10:54:31 -0800, joshbeall@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/forms.html#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/package.http.http-request.file-upload.php

--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация