php - $_FILES operations execute even though IF statement is false -


i trying add file upload ability internal company ticketing system. code works fine actual upload. problem running if there no file, code still executes. have tried many things, using $_files error coding adding select menu choose if want add file or not, code still runs.

it works this:

  1. ticket info processed , entered db = dates, ticket info, email strings, etc
  2. file should validated , uploaded, , moved new folder (named ticket number)
  3. file name , directory path added db.
  4. all info passed notification email sent out.

when script runs, if there no file, db entry made, , info added email, links non-existant directory.

interesting tidbit: code make new directory not execute without file, correct action. confusing thing it's in same block of code.

i have spent day , half trying figure out without resolution. appreciated.

//fileupload $fixedfilename = ""; $fileprocessed = 0;  if($_post['yesfile'] == "yes") { //select option in form -      $allowedexts = array("gif", "jpeg", "jpg", "png", "txt", "pdf", "zip", "doc", "docx", "xls", "xlsx", "pcf");     $varforext = explode(".", $_files["file"]["name"]);     $extension = end($varforext);      if($_files["file"]["size"] < 20000000 && in_array($extension, $allowedexts)) {         if($_files["file"]["error"] > 0) {             //echo "return code: " . $_files["file"]["error"] . "<br>";             $fixedfilename = print_r($_files);         } else {             $fixedfilename = trim(str_replace(' ','_', $_files["file"]["name"]));              $dirtomake = '/var/www/html/eis/uploads/esig/';             $dirtomake .= $_session['lastrid'].'/';             mkdir($dirtomake);              if(move_uploaded_file($_files["file"]["tmp_name"], $dirtomake.$fixedfilename)) {                 //insert filepath/file sql                 $fileprocessed = 1;             }         }     } } 

try turning on error reporting error_reporting(e_all); ini_set("display_errors", "on");

i suspect files array empty, , php seeing undefined $_files["file"]["size"] 0 passes test.

try adding isset($_files["file"]) first test

if(isset($_files["file"]) && $_files["file"]["size"] < 20000000 && in_array($extension, $allowedexts)) { 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -