User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 391,593 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,666 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 3839 | Replies: 8
Reply
Join Date: Oct 2005
Posts: 7
Reputation: leroytrolley is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
leroytrolley leroytrolley is offline Offline
Newbie Poster

Sending pic attachments via PHP form

  #1  
Oct 21st, 2005
Hi

I've just got a nice php form done and I now need my visitors to be able to upload pics and have them sent with the form data. Is that possible in a php form, if so, can anybody point me in the right direction.

Many thanks.

LEE
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2005
Location: Auckland, New Zealand
Posts: 136
Reputation: sarahk is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
sarahk's Avatar
sarahk sarahk is offline Offline
Junior Poster

Re: Sending pic attachments via PHP form

  #2  
Oct 22nd, 2005
I use a free script called phpMailer which lets you do attachments really easily as well as embedded images.

The docs and examples all go with it but if you get stuck just post back here.
Reply With Quote  
Join Date: Jan 2004
Location: Michigan
Posts: 92
Reputation: fsn812 is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 1
fsn812's Avatar
fsn812 fsn812 is offline Offline
Junior Poster in Training

Re: Sending pic attachments via PHP form

  #3  
Oct 24th, 2005
Originally Posted by sarahk
I use a free script called phpMailer which lets you do attachments really easily as well as embedded images.

The docs and examples all go with it but if you get stuck just post back here.

Thanks for the link.
Reply With Quote  
Join Date: Oct 2005
Location: Illinois, USA
Posts: 18
Reputation: JC_McGeekster is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
JC_McGeekster's Avatar
JC_McGeekster JC_McGeekster is offline Offline
Newbie Poster

Re: Sending pic attachments via PHP form

  #4  
Oct 25th, 2005
leroytrolley, if you wish to design your own image uploader or mailer, then I would suggest reading about file uploads. The form you have should probably have some sort of limit on file size or type, like to only allow jpg and gif formats or something. Otherwise, I guess the script listed above would do nicely. Why don't you check out the PHP.Net file uploads page if you want to create your own image upload console: http://us2.php.net/features.file-upload

Good luck.
Reply With Quote  
Join Date: Oct 2005
Posts: 7
Reputation: leroytrolley is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
leroytrolley leroytrolley is offline Offline
Newbie Poster

Re: Sending pic attachments via PHP form

  #5  
Oct 25th, 2005
thanks. but it was a little to advanced for me.

what do I need to add to the attached php code to be able to process image uploads (about 10 images per email).

Leroy
Attached Files
File Type: php emailformexample.php (1.8 KB, 8 views)
Reply With Quote  
Join Date: Oct 2005
Location: Illinois, USA
Posts: 18
Reputation: JC_McGeekster is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
JC_McGeekster's Avatar
JC_McGeekster JC_McGeekster is offline Offline
Newbie Poster

Re: Sending pic attachments via PHP form

  #6  
Oct 25th, 2005
Okay, you have a form, right? Within the form, you add a series of file inputs. Something like:

[HTML]<form action="imgUploader.php" method="POST" enctype="multipart/form-data">
<input type="file" name="photo[]" /><br />
<input type="file" name="photo[]" /><br />
<input type="file" name="photo[]" /><br />
<br />
<input type="submit" value="Upload 'Em!" />
</form>[/HTML]

If you wish, you could do a JavaScript text append thing to where a user clicks a button, and the browser will dynamically add another file input. Anyways, to process these uploads, you of course need something server-side. So, you make your PHP script. Something basic like this should do:

[PHP]<?php
foreach ($_FILES['photo']['error'] as $key => $error) { //For each image...
if ($error == UPLOAD_ERR_OK) { //If no errors...
$tmp_name = $_FILES['photo']['tmp_name'][$key];
$name = $_FILES['photo']['name'][$key];
move_uploaded_file($tmp_name, "images/$name"); //Move image
}
} [/PHP]

Thanks and compliments to the grand PHP manual that I just happen to have. This script should run with PHP 3 and above, but you also have to have a reasonable browser that will handle these uploads. Now, I am not any type of expert on file uploads, as I haven't really messed around with them. But I do know that the form enctype is required, and that the name must have the "[]" thing. This is what creates the array of files; it is required.

Well, I hope this is what you're looking for. Maybe somebody else can help. If not, you may always go to Google and type your query as, "PHP image upload example." And again, good luck.
Reply With Quote  
Join Date: Oct 2005
Posts: 7
Reputation: leroytrolley is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
leroytrolley leroytrolley is offline Offline
Newbie Poster

Re: Sending pic attachments via PHP form

  #7  
Oct 26th, 2005
Many many thanks, but how does the php code know where to send the photos to i.e I cant see where I need put the email adress to send them to.

Sorry if I sound really thick. I'm just a humble designer who can't code for toffee.

Leroy
Reply With Quote  
Join Date: Oct 2005
Location: Illinois, USA
Posts: 18
Reputation: JC_McGeekster is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
JC_McGeekster's Avatar
JC_McGeekster JC_McGeekster is offline Offline
Newbie Poster

Re: Sending pic attachments via PHP form

  #8  
Oct 26th, 2005
Well, the script above will only work to put the images on your server, like an image directory. It will take some modifications to make it function when sending an image in an email, but I believe you could do something to where when the image is uploaded, the link to that image is stored in a variable, and when you send the email, all you do is say here is image one titled "Andrew" and then place in the variable which then displays the link for you or your user to see and use.
Reply With Quote  
Join Date: Jul 2006
Posts: 15
Reputation: mike4 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
mike4's Avatar
mike4 mike4 is offline Offline
Newbie Poster

Re: Sending pic attachments via PHP form

  #9  
Mar 17th, 2008
the first responder told you all u needed there are scripts called mime classes or something which enable you to send emails reeeealy easy! otherwise
it would be
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 11:30 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC