Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP文件提交表_Php_Html_Forms_Web - Fatal编程技术网

PHP文件提交表

PHP文件提交表,php,html,forms,web,Php,Html,Forms,Web,好的,我的表格差不多完成了90%(姓名、电子邮件等) 但是,当用户试图在表单上上载文件时,它只在我的电子邮件中显示文件名,我无法下载它,就像我希望能够下载一样。你们能帮忙吗? 无需执行所有这些操作,只需执行文件输入等。 这是我的HTML表单代码: <form action="" method=POST id=uploadform autocomplete=off> <div class=top-row> <div class=field-wrap>

好的,我的表格差不多完成了90%(姓名、电子邮件等)

但是,当用户试图在表单上上载文件时,它只在我的电子邮件中显示文件名,我无法下载它,就像我希望能够下载一样。你们能帮忙吗?

无需执行所有这些操作,只需执行文件输入等。

这是我的HTML表单代码:

<form action="" method=POST id=uploadform autocomplete=off>
 <div class=top-row>
   <div class=field-wrap>
    <input id="sender" type="text" value="<?php echo !empty($name)?$name:''; ?>" placeholder="Your name" name="name" required>
 </div>
 <div class=field-wrap>
    <input id=senderEmail type="email" value="<?php echo !empty($email)?$email:''; ?>" placeholder="Email@domain.com" name="email" required>
 </div>
</div>
 <div class=top-row>
  <div class=field-wrap>
    <input id="sender" type="text" value="<?php echo !empty($videolink)?$videolink:''; ?>" placeholder="Video Link" name="videolink">
 </div>
  <div class=field-wrap>
    <input id="file" type="file" value="<?php echo !empty($file)?$file:''; ?>" name="file">
   </div>
 </div>
    <textarea id=message type="text" placeholder=Description name=message required><?php echo !empty($message)?$message:''; ?></textarea>
<div class="g-recaptcha" data-sitekey="My google site verification would be here"></div>
 <div class=boxcheckauth>
  <span class=checkboxdescription>By uploading, you agree to the TOS and privacy policy.</span>
 </div>
    <?php if(!empty($errMsg)): ?><div class="errMsg"><?php echo $errMsg; ?></div><?php endif; ?>
    <?php if(!empty($succMsg)): ?><div class="succMsg"><?php echo $succMsg; ?></div><?php endif; ?>
  <center><input type=submit name=submit class="button button-block" value="Upload"/></center>
 </form>

通过上传,您同意TOS和隐私政策。
这是我的PHP提交代码:

if(isset($_POST['submit'])):
if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])):
    //your site secret key
    $secret = 'My google site verification would be here';
    //get verify response data
    $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']);
    $responseData = json_decode($verifyResponse);

    $name = !empty($_POST['name'])?$_POST['name']:'';
    $email = !empty($_POST['email'])?$_POST['email']:'';
    $videolink = !empty($_POST['videolink'])?$_POST['videolink']:'';
    $file = !empty($_POST['file'])?$_POST['file']:'';
    $message = !empty($_POST['message'])?$_POST['message']:'';
    if($responseData->success):
        //contact form submission code
        $to = 'My email would be here';
        $subject = 'Upload form submission';
        $htmlContent = "
            <h1>Upload form submission</h1>
            <p><b>Name: </b>".$name."</p>
            <p><b>Email: </b>".$email."</p>
            <p><b>Video link: </b>".$videolink."</p>
            <p><b>File: </b>".$file."</p>
            <p><b>Message: </b>".$message."</p>
        ";
        // Always set content-type when sending HTML email
        $headers = "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
        // More headers
        $headers .= 'From:'.$name.' <'.$email.'>' . "\r\n";
        //send email
        @mail($to,$subject,$htmlContent,$headers);

        $succMsg = 'Your mail request have submitted successfully.';
        $name = '';
        $email = '';
        $videolink = '';
        $file = '';
        $message = '';
    else:
        $errMsg = 'Robot verification failed, please try again.';
    endif;
else:
    $errMsg = 'Please complete the reCAPTCHA form.';
endif;
else:
    $errMsg = '';
    $succMsg = '';
    $name = '';
    $email = '';
    $videolink = '';
    $file = '';
    $message = '';
endif;
if(设置($\u POST['submit']):
如果(isset($_POST['g-recaptcha-response'])和&!空($_POST['g-recaptcha-response']):
//您的站点密钥
$secret='我的谷歌网站验证将在这里';
//获取验证响应数据
$verifyResponse=文件\u获取\u内容('https://www.google.com/recaptcha/api/siteverify?secret=“.$secret.&response=”.$\u POST['g-recaptcha-response']);
$responseData=json_解码($verifyResponse);
$name=!空($_POST['name'])?$_POST['name']:'';
$email=!空($_POST['email'])?$_POST['email']:'';
$videolink=!空($_POST['videolink'])?$_POST['videolink']:'';
$file=!空($_POST['file'])?$_POST['file']:'';
$message=!空($_POST['message'])?$_POST['message']:'';
如果($responseData->success):
//联络表格提交代码
$to='我的电子邮件会在这里';
$subject='上传表单提交';
$htmlContent=”
上传表格提交
名称:“.$Name。”

电子邮件:“.$Email。”

视频链接:“.$videolink。”

文件:“.$File。”

消息:“.$Message。”

"; //发送HTML电子邮件时始终设置内容类型 $headers=“MIME版本:1.0”。“\r\n”; $headers.=“内容类型:text/html;字符集=UTF-8”。“\r\n”; //更多标题 $headers.='From:'.$name'。“\r\n”; //发送电子邮件 @邮件($to、$subject、$htmlContent、$headers); $succMsg='您的邮件请求已成功提交'; $name=''; $email=''; $videolink=''; $file=''; $message=''; 其他: $errMsg='机器人验证失败,请重试'; endif; 其他: $errMsg='请填写reCAPTCHA表格'; endif; 其他: $errMsg=''; $msg=''; $name=''; $email=''; $videolink=''; $file=''; $message=''; endif;
编辑您的表单:

<form action="" method=POST id=uploadform autocomplete=off>



您需要读取
$\u文件['file']
-您可以将其保存到服务器并通过电子邮件发送链接,或者将内容作为附件嵌入到电子邮件中。因此,我将$\u POST改为$\u文件?旁注:
enctype
很重要,
接受字符集
不用于文件上载。
<form action="" method="POST" id="uploadform" autocomplete="off" accept-charset="UTF-8" enctype="multipart/form-data">