www.webdeveloper.com
Results 1 to 5 of 5

Thread: Validate Image with exif_imagetype but still able to upload non image files

  1. #1
    Join Date
    Dec 2008
    Posts
    123

    Validate Image with exif_imagetype but still able to upload non image files

    I am not sure if my exif_imagetype is coded wrong. It send the email just fine with photos attached. But when I try to attach non image files I am not getting the error message and it still send the email to me. Please help.

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

        
    $photo $_FILES['photo'];

        isset(
    $_POST['submit']);
    $active_keys = array();
    foreach(
    $_FILES[$photo]['name'] as $key => $filename){
    if(!empty(
    $filename)){
        
    $active_keys[] = $key;
    }    }

    foreach(
    $active_keys as $key){    
    switch(
    exif_imagetype($_FILES[$photo]['tmp_name'][$key])) {
    case 
    IMAGETYPE_JPEG:
    case 
    IMAGETYPE_PNG:
        break;
        default:
     echo 
    "{";
     echo        
    "$errors: 'This is no photo..'\n";
     echo 
    "}";
      exit(
    0);
        } }
    $message "some message";
    $mail = new PHPMailer();
    $mail->From     = ('sample@youdomain.net');
    $mail->AddAddress=('sample@youdomain.net');
    $mail->Subject  "Submitted Photos";
    $mail->Body     $message;
    $mail->WordWrap 50;

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

    $mail->Send();


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

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,175
    It might be interesting to see if your $active_keys array actually has some data before you loop through it, e.g.:
    PHP Code:
    }

    error_log("active keys array: ".print_r($active_keys1));

    foreach(
    $active_keys as $key){ 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Dec 2008
    Posts
    123
    I have pasted your above code in the script and there is nothing printed. It still just go through and send the email.

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,175
    error_log() will write it to the applicable PHP error log. If you want to just output it to the browser for debugging purposes (i.e. you don't want it in the live code):
    PHP Code:
    echo "<pre>Active Keys:".PHP_EOL.var_export($active_keystrue)."</pre>"
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Dec 2008
    Posts
    123
    I put the code as follow but still didn't get any message. However, I no longer receive the email either. please help.


    PHP Code:
        isset($_POST['submit']);
        
    $active_keys = array();
        foreach(
    $_FILES[$photo]['name'] as $key => $filename)
        {
        if(!empty(
    $filename))
        {
        
    $active_keys[] = $key;
        }    }

    echo 
    "<pre>Active Keys:".PHP_EOL.var_export($active_keystrue)."</pre>";  

    foreach(
    $active_keys as $key){  
            switch(
    exif_imagetype($_FILES[$photo]['tmp_name'][$key])) {
            case 
    IMAGETYPE_JPEG:
            case 
    IMAGETYPE_PNG:
            break;
            default:
            echo 
    "{";
            echo        
    "$errors: 'This is no photo..'\n";
            echo 
    "}";
            exit(
    0);
            } } 

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