并非在POST中传递所有变量[重复]

问题描述 投票:0回答:1

此问题已经在这里有了答案:

我正在(应该是)一个简单的页面和脚本上工作,以发送带有附件的电子邮件,但是遇到了一个问题,即在POST中未发送最后一个值。如果我能弄清楚的话就很危险。

发送页面的HTML为:

    <form action="contact_reply.php" method="post" name="form1"  required="required" id="form1" enctype="multipart/form-data" >
    <p>
    <input type="hidden" name="PageURL" value="<?php echo GetSelfURL() ?>" />
  </p>
    <p>Your Name<br />
    <span id="sprytextfield1">
    <input name="MSG_Name" type="text"  required="required" id="MSG_Name" tabindex="1" size="70" maxlength="70" />
</span>
</p>

    <p>Your Email Address<br />
    <span id="sprytextfield2">
    <input name="MSG_Email" type="text"  required="required" id="MSG_Email" tabindex="2" size="70" maxlength="70" />
    </span>
    </p>

    <p>Subject<br />
    <span id="sprytextfield3">
    <input name="MSG_Subject" type="text"  required="required" id="MSG_Subject" tabindex="3" size="70" maxlength="70" />
    </span>
    </p>

    <p>Message<br />
    <span id="sprytextarea1">
    <textarea name="MSG_Text"  required="required" id="MSG_Text" cols="70" rows="5" tabindex="4"></textarea>
    </span>
</p>

    <?php
if ($Allow_Attachments)
{
?>            
    <p>Attachment (images only):
    <input name="MSG_Attachment" type="file" id="MSG_Attachment" tabindex="5" accept="image/*" multiple >
</p>
<?php
}
?> 
  <p align="center">
    <input 
    type="submit" 
  name="Contact_SendBtn" 
  id="Contact_SendBtn" 
  value="Submit" 
  tabindex="5"
  vakue="send"
    style="width:60px"/>
   </p>
</form>

接收端的php是:

    function CheckMessageInfo()
{
global $MSG_Name, $MSG_Email, $MSG_Subject, $MSG_Text, $MSG_Attachment, $MSG_Error;

$MSG_Error = '';

echo "<p>".var_dump($_POST)."</p>"; 

if ($_SERVER["REQUEST_METHOD"] == "POST") 
{
if (empty($_POST["MSG_Name"])) 
    {
  $MSG_Error .= "A name is required. ".PHP_EOL;
  } 
    else
    {
  $MSG_Name = test_input($_POST["MSG_Name"]);
    if (!preg_match("/^[a-zA-Z ]*$/",$MSG_Name)) 
        {
    $MSG_Error .= "Only letters and spaces are allowed in the name. ".PHP_EOL;
    }
    }

  if (empty($_POST["MSG_Email"])) 
    {
        $MSG_Error .= "An email address is required. ".PHP_EOL;
    }
    else
    {
    $MSG_Email = test_input($_POST["MSG_Email"]);
    if (!filter_var($MSG_Email, FILTER_VALIDATE_EMAIL)) 
        {
    $MSG_Error .= "Invalid email format. ".PHP_EOL;
    }
}

  if (empty($_POST["MSG_Subject"])) 
    {
        $MSG_Error .= "A subject for the message is required. ".PHP_EOL;
    }
    else
    {
        $MSG_Subject = filter_var($_POST["MSG_Subject"],FILTER_SANITIZE_STRING);
}

  if (empty($_POST["MSG_Text"])) 
    {
        $MSG_Error .= "The message's text is required. ".PHP_EOL;
    }
    else
    {
        $MSG_Text = filter_var($_POST["MSG_Text"],FILTER_SANITIZE_STRING);
}

    if (empty($_POST["MSG_Attachment"]))
    {
        $Allow_Attachments = FALSE;
    }
    else
    {
        $MSG_Attachment = $_POST["MSG_Attachment"];
    }
    return TRUE;
}
else
{
    return FALSE;
}
}

var_Dump行给我这个:

array(6) {
  ["PageURL"]=> string(39) "www.vintagebankantiques.net/contact.php" 
  ["MSG_Name"]=> string(4) "Mike"
  ["MSG_Email"]=> string(21) "[email protected]" 
  ["MSG_Subject"]=> string(4) "test"
  ["MSG_Text"]=> string(21) "improved echo $_POST."
  ["Contact_SendBtn"]=> string(6) "Submit"
}

“ MSG_Attachment”变量未列出。去哪儿了?

php file post
1个回答
0
投票

您可以通过]获得MSG_Attachment的值>

$_FILES['MSG_Attachment']["tmp_name"]

//if MSG_Attachment is array type
$_FILES['MSG_Attachment']["tmp_name"][0]
$_FILES['MSG_Attachment']["tmp_name"][1] 

因为MSG_Attachment输入类型是文件,所以无法进入POST。

您也可以参考此link

© www.soinside.com 2019 - 2024. All rights reserved.