www.webdeveloper.com
Results 1 to 6 of 6

Thread: fileinfo not restricting pdf only

  1. #1
    Join Date
    Dec 2008
    Posts
    98

    fileinfo not restricting pdf only

    I am using the below script to validate if the uploaded files are pdf and if it is send it with phpmailer. I did not received any error message even when I attached non pdf file . Also, it send the email without attachment. Please help.

    PHP Code:
        ob_start();
        require(
    "class.phpmailer.php");

        if(isset(
    $_FILES['upload']['tmp_name'])){
        
    $finfo finfo_open(FILEINFO_MIME_TYPE);
        
    $mime=finfo_file($finfo$_FILES['upload']['tmp_name']);
        if(
    $mime=='application/pdf'){
               }}

        
    $message "some message";
        
    $mail = new PHPMailer();
        
    $mail->From     = ('sample@youdomain.net');
        
    $mail->AddAddress=('sample@youdomain.net');
        
    $mail->Subject  "Submitted files";
        
    $mail->Body     $message;
        
    $mail->WordWrap 50;

        foreach(
    $_FILES['upload']['tmp_name'] as $upload
        if(!empty(
    $upload)) {
        
    $mail->AddAttachment($upload);
        }
        
    $mail->Send();

        
    header("Location: thankyou.php");
        exit();     
        }} 

  2. #2
    Join Date
    Mar 2013
    Location
    Herat
    Posts
    6
    did the script send the attachment,email ?

  3. #3
    Join Date
    Dec 2008
    Posts
    98
    It send just the email with no attachment.

  4. #4
    Join Date
    Mar 2013
    Location
    Herat
    Posts
    6
    ob_start();
    require("class.phpmailer.php");

    if(isset($_FILES['upload']['tmp_name'])){
    $finfo = finfo_open(FILEINFO_MIME_TYPE);
    $mime=finfo_file($finfo, $_FILES['upload']['tmp_name']);
    if($mime=='application/pdf'){


    $message = "some message";
    $mail = new PHPMailer();
    $mail->From = ('sample@youdomain.net');
    $mail->AddAddress=('sample@youdomain.net');
    $mail->Subject = "Submitted files";
    $mail->Body = $message;
    $mail->WordWrap = 50;

    foreach($_FILES['upload']['tmp_name'] as $upload)
    if(!empty($upload)) {
    $mail->AddAttachment($upload);
    }
    $mail->Send();

    }

    header("Location: thankyou.php");
    exit();
    }
    this will work.

  5. #5
    Join Date
    Dec 2008
    Posts
    98
    I tried the script you provided but now I didn't get the email anymore even when attaching pdf file. Any idea?

  6. #6
    Join Date
    Dec 2008
    Posts
    98
    Anyone please help? I couldn't figure it out myself.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles