| | |
Sending pic attachments via PHP form
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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.
The docs and examples all go with it but if you get stuck just post back here.
•
•
•
•
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.
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.
Good luck.
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.
[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.
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.
![]() |
Similar Threads
- PHP Form Validation ??? (PHP)
Other Threads in the PHP Forum
- Previous Thread: Display random image from database and...
- Next Thread: The best community software?
| Thread Tools | Search this Thread |
apache api archive array autocomplete beginner binary broken cakephp checkbox class cms code cron curl database dataentry date display duplicates dynamic ebooks echo email emptydisplayvalue error execute explodefunction file files firstoptioninphpdroplist folder form forms function functions google href htaccess html image include insert ip javasciptvalidation javascript joomla keywords limit link login mail matching mediawiki menu mlm multiple mysql number oop paypal pdf php phpincludeissue problem query radio random recursion recursive remote script search server sessions shot sms source sp space speed sql subdomain subscription syntax system table tag tutorial tutorials update upload url validator variable vbulletin video web white youtube





