title: Krajee file input invalid json response
body: <p>I tried to integrate krajee file-input into my existing form. <a href="http://plugins.krajee.com/file-input/demo#ajax-demo" rel="nofollow noreferrer">DEMO SITE</a></p>
  <p>When i browse a file from my computer and click upload button (built-in with the plugin), i got this error: SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data.</p>
  <p>The author of this plugin told me that i have to write valid json response in my php file for this to work but he did not have time to help individual case like mine. So I read the documentation from the website, it has this part:(you can find it on the demo site above)</p>
  <blockquote>
  <p>Sending Data (from server)</p>
  <p>Your server method as set in uploadUrl must send data back as a json encoded object. The only key you must send is the error which will be the error message for the upload and will help the plugin to identify error in the file upload. For example the response from server would be sent as {error: 'You are not allowed to upload such a file.'}. Note: The plugin will automatically validate and display ajax exception errors.</p>
  <p>IMPORTANT</p>
  <p>You MUST send a valid JSON response from your server, else the upload process will fail. Even if you do not encounter any error, you must at least send an empty JSON object {} from your server.</p>
  <p>To trap and display a validation error, your JSON response data must include the error key, whose value will be the error HTML markup to display. This is to be setup as mentioned above.</p>
  </blockquote>
  <p>Unfortunately, I can't understand it because I am just a new php learner and this is out of my scope. But I have my php file here, hope some expert can help me to add the json response to it as the documentaion explained above. Thank you very much in advance!</p>
  <p>Here is my php file:</p>
  <pre><code>&lt;?php
  if(isset($_POST[&quot;submit&quot;])){
  require(&quot;../configs/dbconnect.php&quot;);
  /*Form variable   */
  $owner = mysql_real_escape_string($_POST[&quot;owner&quot;]);
  $title = mysql_real_escape_string($_POST[&quot;title&quot;]);
  $description = mysql_real_escape_string($_POST[&quot;description&quot;]);
  $city = mysql_real_escape_string($_POST[&quot;city&quot;]);
  $brand = mysql_real_escape_string($_POST[&quot;brand&quot;]);
  $marketprice = mysql_real_escape_string($_POST[&quot;marketprice&quot;]);
  $price = mysql_real_escape_string($_POST[&quot;price&quot;]);
  $phone = mysql_real_escape_string($_POST[&quot;phone&quot;]);
  /*** the upload directory ***/
  $upload_dir= 'uploads';
  
  /*** numver of files to upload ***/
  $num_uploads = 5;
  
  /*** maximum filesize allowed in bytes ***/
  $max_file_size  = 5000000;
  
  /*** the maximum filesize from php.ini ***/
  $ini_max = str_replace('M', '', ini_get('upload_max_filesize'));
  $upload_max = $ini_max * 1024;
  
  /*** a message for users ***/
  $msg = 'Please select files for uploading';
  
  /*** an array to hold messages ***/
  $messages = array();
  $err=array();
  
  /*** check if a file has been submitted ***/
  if(isset($_FILES['file']['tmp_name']))
  {
      /** loop through the array of files ***/
      for($i=0; $i &lt; count($_FILES['file']['tmp_name']);$i++)
      {
          // check if there is a file in the array
          if(!is_uploaded_file($_FILES['file']['tmp_name'][$i]))
          {
              $messages[] = 'No file uploaded';
          }
          /*** check if the file is less then the max php.ini size ***/
          //elseif($_FILES['image']['size'][$i] &gt; $upload_max)
          //{
          //    $messages[] = &quot;File size exceeds $upload_max php.ini limit&quot;;
          //}
          // check the file is less than the maximum file size
          elseif($_FILES['file']['size'][$i] &gt; $max_file_size)
          {
              $messages[] = &quot;File size exceeds $max_file_size limit&quot;;
          }
          else
          {
              //$temp = explode(&quot;.&quot;, $_FILES[&quot;file&quot;][&quot;name&quot;][$i]);
              //$extension = end($temp);
              //$name[$i] = sha1(microtime()) . &quot;.&quot; . $extension;
              $name[$i]=$_FILES[&quot;file&quot;][&quot;name&quot;][$i];
              // copy the file to the specified dir 
              if(move_uploaded_file($_FILES['file']['tmp_name'][$i],$upload_dir.'/'.$name[$i]))
              {
                  /*** give praise and thanks to the php gods ***/
                  $messages[] = $name[$i].' uploaded';
                  $image_path[$i]=$upload_dir.'/'.$name[$i];
              }
              else
              {
                  /*** an error message ***/
                  $messages[] = 'Uploading '.$name[$i].' Failed';
              }
          }
      }
  }
  $image_path_string=serialize($image_path);
  $sql = &quot;INSERT INTO memberpost(owner, title, description, city, brand, marketprice, price, phone, image) VALUES ('$owner', '$title','$description','$city','$brand','$marketprice','$price','$phone', '&quot; . $image_path_string . &quot;')&quot;;
  $result = mysql_query($sql) or die (&quot;Could not insert data into DB: &quot; . mysql_error());
   if(sizeof($messages) != 0)
  {
      foreach($messages as $err)
      {
          echo $err.'&lt;br /&gt;';
      }
  }
  }
  ?&gt;
  </code></pre>