2016-12-20 21 views
0

私のコードを変更して、いくつかの拡張機能のみを受け入れることができます。例えば、私は、配列をプッシュしようとすると、拡張子が、いくつかの配列内にあるかどうかを見ることができ、許可された拡張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(); 

私はいくつかのコードを追加しようとしたが、成功事例のを作っていけない:

は私のコードを見て?

ありがとうございました。

+0

まず許さ拡張子($ AllowedFileTypes)の配列を構築する:あなたがフォームを送信する前に、ファイルの種類/拡張子を確認したい場合は

は、ファイル入力のためのjQueryの検証を見てみましょう。 ($ FileExtension、$ AllowedFileType) – JustBaron

+0

のように、 '$ allowed = array( 'pdf'、 'doc'、 'docx')のように、 、 'gif'、 'jpeg'、 'jpg'、 'png'、 'rtf'、 'txt'、 'zip'); –

+0

そうです。次に、tmp localtion – JustBaron

答えて

0

あなたがそれらを移動する前にアップロードされたファイルの種類を確認したいと仮定:

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

注:あなたはあなたの要件に合うように、変数を修正する必要があります。 、https://stackoverflow.com/a/20929391/715105

関連する問題