title: PHP - Problem with fileupload (index.php->custom.js->function.php)
body: <p><strong>Hi Guys!</strong>
  Im having isusses with my wordpress plugin. Im trying to upload a file through a form.
  The problem is that I can't store my type="file" in the database.
  I have some other functions where I put values like text inside my database without any problems.</p>
  
  <p>I dont know if im supposed to change the custom.js function file or what to do...</p>
  
  <p>Can u guys help me out?</p>
  
  <p><em>thx for helping.</em> </p>
  
  <p>This is my Index.php            </p>
  
  <pre><code>&lt;form id="frmCreateFile" class="form-horizontal" action="javascript:void(0)" method="post" 
                  enctype="multipart/form-data"&gt;
                  Select Image File to Upload:
                  &lt;input id="file" type="file" name="file"&gt;
                  &lt;input type="submit" name="submit" value="Upload"&gt;
              &lt;/form&gt;
  </code></pre>
  
  <p>This is my Custom.js</p>
  
  <pre><code>jQuery("#frmCreateFile").validate({
          submitHandler:function(){
              var postdata = jQuery("#frmCreateFile").serialize()+"&amp;action=crm_request&amp;param=create_file";
              jQuery.post(crm_ajax_url, postdata, function(response){
                  var data = jQuery.parseJSON(response);
                  location.reload();
              })
          }
      });
  </code></pre>
  
  <p>This is my Function.php</p>
  
  <pre><code>global $wpdb;
  $param = isset($_REQUEST['param']) ? $_REQUEST['param'] : "";
  
  if(!empty($param) &amp;&amp; $param=='create_file'){
  
      $customerId = '358';
  
      // File upload path
      $targetDir = VEOSOFT_CRM_DIR . "/uploads/";
      echo $targetDir;
      $fileName = basename($_FILES["file"]["name"]);
      $targetFilePath = $targetDir . $fileName;
      $fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION);
  
      if(isset($_POST["submit"]) &amp;&amp; !empty($_FILES["file"]["name"])){
  
          // Allow certain file formats
          $allowTypes = array('jpg','png','jpeg','gif','pdf');
          if(in_array($fileType, $allowTypes)){
              // Upload file to server
              if(move_uploaded_file($_FILES["file"]["tmp_name"], $targetFilePath)){
                  // Insert image file name into database
                  $insert = $wpdb-&gt;query("INSERT into wpwh_veosoft_crm_file (fileName, uploadDate, customer_Id) VALUES ('".$fileName."', NOW(),$customerId)");
                  if($insert){
  
                      $statusMsg = "The file ".$fileName. " has been uploaded successfully.";
                  }else{
                      $statusMsg = "File upload failed, please try again.";
                  } 
              }else{
                  $statusMsg = "Sorry, there was an error uploading your file.";
              }
          }else{
              $statusMsg = 'Sorry, only JPG, JPEG, PNG, GIF, &amp; PDF files are allowed to upload.';
          }
      }else{
          $statusMsg = 'Please select a file to upload.';
      }
  }
  </code></pre>
  
  <p>After clicking on submit my database is inserting a new row in my table with this value:</p>
  
  <pre><code>Id = 51
  FileName = (empty)
  Date = 2019-12-17
  </code></pre>