I want to create a form to allow visitors upload files and send the uploaded files to me with swiftmailer. I am trying to accomplish this with the below code but don't know how to put it in swiftmailer attach() function after validation and make sure all attached file is sent? please help. Also, if there is a better way to do this please let me know. Thanks.
I copied this script from another side. What is the purpose ofHTML Code:<form action="" method="post" enctype="multipart/form-data"> <p>Pictures: <input type="file" name="pictures[]" /> <input type="file" name="pictures[]" /> <input type="file" name="pictures[]" /> <input type="submit" value="Send" /> </p> </form>PHP Code:$uploaded_array[] .= "Uploaded file '".$name."'.<br/>\n";
PHP Code:<?php
foreach ($_FILES["attachment"]["error"] as $key => $error)
{
$tmp_name = $_FILES["attachment"]["tmp_name"][$key];
if (!$tmp_name) continue;
$name = basename($_FILES["attachment"]["name"][$key]);
if ($error == UPLOAD_ERR_OK)
{
if ( move_uploaded_file($tmp_name, "/tmp/".$name) )
$uploaded_array[] .= "Uploaded file '".$name."'.<br/>\n";
else
$errormsg .= "Could not move uploaded file '".$tmp_name."' to '".$name."'<br/>\n";
}
else $errormsg .= "Upload error. [".$error."] on file '".$name."'<br/>\n";
}
?>


Reply With Quote
Bookmarks