允许扩展 phpmailer [英] Allowed extension phpmailer

查看:51
本文介绍了允许扩展 phpmailer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

how could i change my code to only accept some extensions.

看我的代码:

  <?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();

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

i have tried add some codes , but dont made sucess , for example , could i try push the array and see if the extension are inside some array ?

谢谢.

推荐答案

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

Presuming you want to check the uploaded file types before moving them:

$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
}

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

Note: You may have to amend the variables to suit your requirements.

如果您希望在提交表单之前验证文件类型/扩展名,请查看文件输入的 jQuery 验证:https://stackoverflow.com/a/20929391/715105

If you wish to validate the file type/extension before submitting the form, take a look at jQuery validation for file input: https://stackoverflow.com/a/20929391/715105

这篇关于允许扩展 phpmailer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆