PHP sending mail attachments

白昼怎懂夜的黑 提交于 2019-12-03 20:49:19

Use move_uploaded_file() to move the file to a temporary location; attach it to the mail from there and delete it afterwards (or keep it, whatever you want to do).

See the PHP manual on file uploads for a detailed example.

Your complete solution should look like this:

1) html

<form method="post" action="myupload.php">
<input type="file" name="uploaded_file" />
<input type="submit" />
</form>

2) myupload.php

<?php
$uploads_dir = '/uploads';
foreach ($_FILES["uploaded_file"]["error"] as $key => $error) {
    if ($error == UPLOAD_ERR_OK) {
        $tmp_name = $_FILES["uploaded_file"]["tmp_name"][$key];
        $name = $_FILES["uploaded_file"]["name"][$key];
        move_uploaded_file($tmp_name, "$uploads_dir/$name");
    }
}
?>

Taken from http://php.net/manual/en/function.move-uploaded-file.php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!