I am trying to create a webform that has 4 upload field. I want to have the uploaded file email to me with phpmailer. I need to know how to validate that the uploaded files are images, attached via phpmailer and send to an email address. I found the below code that will move the file to a folder but I want to attached the files to email without moving them. Is that possible and how do I do it? Any help will be much appreciated.
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
$mail->AddAttachment($target_path);
Best way I know of to verify a file is an image is to find out if getimagesize() returns a non-empty array.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Thanks NogDog. Can you please provide an example of how to use getimagesize() function? Also, do I just use the $mail->AddAttachment, is that mean I don't need to do the coding I have posted? thanks for your help.
if(getimagesize($_FILES['uploadedfile']['tmp_name']) == false) { // it's not an image (or at least any type PHP recognizes) }
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks