email uploaded image

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ben_albrechts
Forum Commoner
Posts: 33
Joined: Wed Oct 26, 2005 3:33 am

email uploaded image

Post by ben_albrechts »

Hello,

I now have a form on my site for the clients to fill in all their details aswell as upload an image.
Now I would need for when they click the submit button ,that the information they submitted aswell as the image they uploaded are displayed. AND it also needs to be emailed to me in one email with the uploaded image as an attachement to the email with the details submitted.

How can I do this?
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

go to the php manual, look up file upload and mail.
eh..
http://us2.php.net/features.file-upload
http://us2.php.net/manual/en/function.mail.php
though for mail i recommend using
http://phpmailer.sourceforge.net/
ben_albrechts
Forum Commoner
Posts: 33
Joined: Wed Oct 26, 2005 3:33 am

Post by ben_albrechts »

Right , i had a look at those links u gave me.
I did know how to email the data that was submitted and how to display it.
But since I added the 'image upload' to my form , it doesn't work anymore.
The image won't display together with the text and the email doesn't include the image either.
:?
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

yeah you gotta do the following on your form...

<form enctype="multipart/form-data"

did you do that?
ben_albrechts
Forum Commoner
Posts: 33
Joined: Wed Oct 26, 2005 3:33 am

Post by ben_albrechts »

yea i did
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

then post your code so we can see it.
ben_albrechts
Forum Commoner
Posts: 33
Joined: Wed Oct 26, 2005 3:33 am

Post by ben_albrechts »

The code is rather long as I have about a hundred switch cases in it.
but the problem that i dont understand is. After people click submit , there image should be displayed on the thank you page.
But don't you need to know the url to display and image? I know the folder where the images should be moved to , but if i want to show them , i need to use echo '..... right? but what comes after echo?
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

um.. a simple html img tag:-D
ben_albrechts
Forum Commoner
Posts: 33
Joined: Wed Oct 26, 2005 3:33 am

Post by ben_albrechts »

yes , but i dont understand. It is so that the image is saved in a folder under the name that it was on the visitor's pc . So it can be anything , how do i make an img tag then that it does show?
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

no.once they upload it it's on your server...and you should know where you placed it..and what you named it....
ben_albrechts
Forum Commoner
Posts: 33
Joined: Wed Oct 26, 2005 3:33 am

Post by ben_albrechts »

i have this :

Code: Select all

copy ($_FILES['imagefile']['tmp_name'], "files/".$_FILES['imagefile']['name']) 
    or die ("Could not copy");
it copies the image to a folder called files. But it doesnt change the name.
So wot do I put to display this image on the thankyou page?

Argh it's all confusing me way too much lol
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

Code: Select all

echo "<img src="files/".$_FILES['imagefile']['name']." />";
ben_albrechts
Forum Commoner
Posts: 33
Joined: Wed Oct 26, 2005 3:33 am

Post by ben_albrechts »

if i make a seperate form for the image upload and i put

Code: Select all

copy ($_FILES['imagefile']['tmp_name'], "files/".$_FILES['imagefile']['name']) 
    or die ("Could not copy");
it does work and moves and saves the image in a folder called files

but if i put it in an existing form that also has text input and all , it doesnt work and the image isnt uploaded nor saved in that folder.

Also even if i use a seperate form for the file upload , I can't manage to get the image displayed on the thank you page.
Can anybody please help me?

I also need the image together with the text my users wrote in the form to be emailed to me , and that won't work either
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Are you sure you are retreiving the file name from the database? I suspect your trying to use the $_FILE array to determine the image name, but the $_FILES information will only exist on the page execution of the upload. Post your code where you are trying to show the image.
ben_albrechts
Forum Commoner
Posts: 33
Joined: Wed Oct 26, 2005 3:33 am

Post by ben_albrechts »

Code: Select all

echo "<img src="files/".$_FILES['imagefile']['name']." />";
Post Reply