表单提交文件附加

问题描述 投票:-7回答:2

我有一个上传部分的表单。上传文件后,用户单击“发送”按钮。之后,我想将文件作为附件发送到接收者邮件

php html css forms
2个回答
0
投票
if( isset($_POST['myFile']) ){

    $attachname8=$_FILES['myFile']['name'];
    $attachment8='';

    $output_dir="report/";
    //Filter the file types , if you want.

    if(!empty($attachname8))
    {
        if ($_FILES["myFile"]["name"] > 0)
        {
              echo "Error: " . $_FILES["myFile"]["error"] . "<br>";
        }
        else
        {
             //move the uploaded file to uploads folder;
             move_uploaded_file($_FILES["myFile"] ["tmp_name"],$output_dir.$_FILES["myFile"]["name"]);
             $attachment8="report/".$_FILES["myFile"]["name"];

        }
    }
}

-1
投票

如果你的表单中有<input type='file' name='myFile' />,那么在提交时,你需要的只是在你的php文件中获取这个命名字段

if( isset($_POST['myFile']) ){
// means there is file submitted
// do process it here (store, edit, delete, whatever)
}
© www.soinside.com 2019 - 2024. All rights reserved.