表单提交文件附加

时间:2018-05-25 06:00:51

标签: php html css forms

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

2 个答案:

答案 0 :(得分: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 :(得分:-1)

如果您的表单中有<input type='file' name='myFile' />,则在提交时,您只需要在php文件中获取此命名字段

if( isset($_POST['myFile']) ){
// means there is file submitted
// do process it here (store, edit, delete, whatever)
}