允许扩展 phpmailer

Allowed extension phpmailer

我如何更改我的代码以仅接受某些扩展。

看看我的代码:

  <?php
    ob_start();
   $_SESSION['nomecomp'] = $_POST['nomecomp'];

       $email_env = $_POST['email_env'];
      if (isset($email_env)) {
   //variaveis vindas da pagina
    $varcritico = $_POST['varcritico'];
    $nomecomp = $_POST['nomecomp'];
    $chapa = $_POST['chapa'];
   $funcao = $_POST['funcao'];
      $setor = $_POST['setor'];
      $unidade = $_POST['unidade'];
      $deschelp = $_POST['deschelp'];





     //variveis do modal
     //$email_env = $_POST['email_env'];
      //$senha_env = $_POST['senha_env'];






       <td>$deschelp</td>



        </tr>
       </table>'";

        /**
       * PHPMailer multiple files upload and send example
           */

        $msg = '';
           //if (array_key_exists('userfile', $_FILES)) {

         // Create a message
       // This should be somewhere in your include_path
          include ("lib/PHPMailerAutoload.php");
        $mail = new PHPMailer();

我已经尝试添加一些代码,但没有成功,例如,我可以尝试推送数组并查看扩展名是否在某个数组内吗?

谢谢。

假设您想在移动之前检查上传的文件类型:

$AllowedFileTypes = array("pdf","txt"); // build array
$FileName = $_FILES['userfile']['name']; // get filename of file input
$FileType = end((explode(".", $FileName))); // get file type/extension
if(in_array($FileType, $AllowedFileTypes)){ // check to see if file type is allowed
 // perform copy/move file
}
else{
 // ignore/alert/whatever
}

注意:您可能需要修改变量以满足您的要求。

如果您希望在提交表单之前验证文件 type/extension,请查看 jQuery 文件输入验证: