|Problems? Is your data what you think it is?|
(jcwren) Re: Uploading a fileby jcwren (Prior)
|on Jun 08, 2000 at 16:45 UTC||Need Help??|
What, exactly, is the question? Are you looking for code to do this, an explanation of the framework for how to do this, or general ideas for the user interface?
I recently had to do something similiar. I manage (such as one does) a large database of batteries. Users need to be able to upload pictures of batteries in to the database. There is a page with a couple of fields on, where the user enters the serial number, describes the picture (intact, exploded, top view, whatever), and, most importantly, the path to the file on their local machine. This is done using a INPUT field, with a type of FILE.
When the user clicks 'Go', the file will be submitted as part of the POST data. Note that the ENCTYPE on the FORM with the INPUT button must be set to "multipart/form-data".
Let's say that your input field is named 'photofile'. The following code
gets the filename the user wants to upload from his local drive, and a file handle to said file. You then proceed to use a loop
to read the data into a string. Now I perform some other processing on the file data before it's loaded into the database, but you could copy it straight to a file (I pump the image through ImageMagick to create a thumbnail, do some normalization, and limit the dimensions of the picture). You *absolutely* need to set a limit on how much data you'll accept or some weenie may try to upload a 1,000,000 x 1,000,000 x 24 bit image of Britney Spears to see how you'll handle it.
This is the basic form of what you're trying to do. If you can clarify the question some, a little more specific help can probably be provided.