【问题标题】:Form submit file attach表格提交文件附件
【发布时间】:2018-11-04 10:55:44
【问题描述】:

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

【问题讨论】:

标签: php html css forms


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:
    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"];
    
            }
        }
    }
    

    【讨论】:

    • 这个答案比我的好
    猜你喜欢
    • 1970-01-01
    • 2013-01-28
    • 1970-01-01
    • 2015-01-10
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多