Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > attaching files to forms

attaching files to forms
Thread Tools
Forum Regular
Join Date: Nov 2000
Status: Offline
Reply With Quote
Apr 3, 2002, 11:11 AM
 
I want to create a form that allows people to attach jpegs that are sent to me when the form is processed. How do you do this? So far, I've created a browse button that looks for the file and attaches it. But when the form is processed, all I receive is the title of the picture, not the file.

Any help would be appreciated. Thanks.
     
Mac Elite
Join Date: Oct 1999
Location: San Jose, Ca
Status: Offline
Reply With Quote
Apr 3, 2002, 02:00 PM
 
I've done this both in PHP and perl, and the methods are very different in both. You will have to be more specific about what language you are using before we can help you.

Oh.. and the PHP documentation is very clear on this sort of thing. It is available online. (RTFM)
     
Senior User
Join Date: May 2001
Location: Nottingham, UK
Status: Offline
Reply With Quote
Apr 4, 2002, 04:41 AM
 
Originally posted by dvwannabe:
<STRONG>I want to create a form that allows people to attach jpegs that are sent to me when the form is processed. How do you do this? So far, I've created a browse button that looks for the file and attaches it. But when the form is processed, all I receive is the title of the picture, not the file.

Any help would be appreciated. Thanks.</STRONG>
what server you running this on?
     
Forum Regular
Join Date: Nov 2000
Status: Offline
Reply With Quote
Apr 4, 2002, 09:20 AM
 
I'm using a Linux server. I've been using PERL for processing my forms. Right now, I have a pretty basic form processing cgi script in place.
     
Senior User
Join Date: May 2001
Location: Nottingham, UK
Status: Offline
Reply With Quote
Apr 5, 2002, 04:00 AM
 
Hi there

i'm sure you'll have PHP on there right? If so, this is what i use:

First you need the form, which you already got, but you need to modify the 'form' tag a bit:

&lt;form action="upload.php" method="post" enctype="multipart/form-data"&gt;
&lt;input type="file" name="img1" size="30"&gt;&lt;/p&gt;
&lt;input type="submit" name="submit" value="Upload File"&gt;
&lt;/form&gt;

notice the "enctype" but in the form - tells the server there's more than just text coming up.

Now, the upload.php script, really simple:


&lt;?
if ($img1_name != "") {

copy("$img1", "/your/directory/path/$img1_name")
or die("Couldn't copy the file!");

} else {

die("No input file specified");
}
?&gt;

&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Successful File Upload!&lt;/title&gt;
&lt;body&gt;

&lt;h1&gt;Success!&lt;/h1&gt;

&lt;P&gt;You sent: &lt;? echo "$img1_name"; ?&gt;, a &lt;? echo "$img1_size"; ?&gt;
byte file with a mime type of &lt;? echo "$img1_type"; ?&gt;.&lt;/p&gt;

&lt;/body&gt;
&lt;/html&gt;


that's it. Just make sure you got write permission on both your php temp directory and the directory the file is copying into, otherwise you'll get some nasty errors.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:05 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2