PDA

View Full Version : Getting the viewer to upload an image


cozmek
01-01-2005, 04:57 PM
Hi and Happy New Year.

Can anyone give me advice on the followign.

I am creating a form for a site incorporating the viewers details, e.g. age, address,telephone number....usual info stuff.

I am using a form that I have used in projects before and just tweaking certain information (Hah! like where it will be sent to....made that mistake before) so I have no real problems there.....My main problem is working out how to allow them to upload an image with their details and getting this sent with the form?

Is there a simple way of doing this that i am unaware of (Please say yes!!!) or, if not, could someone please direct me in the right direction?

Thanks in advance folks.

MrQuietGuy
01-01-2005, 05:41 PM
I haven't done it, but my PHP book describes how to do it. You will, of course, need some kind of server-side script to process the file on the server. Here's what you put in the form:

<FORM ACTION="upload.php" METHOD=POST ENCTYPE="multipart/form-data">
Submit this file: <INPUT TYPE=FILE NAME="userfile">

<INPUT TYPE=SUBMIT>

</FORM>

The Action attribute, as usual, specifies where to go when the file is uploaded. This would be the page that processes the file (i.e., saves it to wherever you want to put it on the server).

Be sure to set the ENCTYPE as specified above.

What the server-side script does depends on the language you use. The file is uploaded to a temporary directory on the server (as specified by the TEMPDIR environment variable).

Here's an example of how to process the file on the server, using PHP (This is what's in upload.php).

<HTML>
<!-- upload.php -->
<?
// Copy the file to C:\upload.txt. Remember to escape backslashes!
if (copy($userfile, "C:\\upload.txt")) {
echo("File successfully copied!;
} else {
echo("Error: failed to copy file...);
}
// Destroy the file now we've copied it
unlink($userfile);
?>
</HTML>

The above info was found in the book "Professional PHP Programming" by Wrox.

Since I haven't ever done this, I probably won't be much help beyond this.
Also, if you use a different scripting language, I can't help either.