title: Getting ERROR 419 (unknown status) while uploading image Laravel 5.5
body: <p>I am new in laravel and i am trying to integrate pl uploader inside for image uploading.</p>
  
  <p>I am getting unknown status error when i upload image.</p>
  
  <p>Here is the script i am using in view:</p>
  
  <pre><code> var uploader = new plupload.Uploader({
          runtimes : 'html5,flash,silverlight,html4',
          browse_button : 'bg_upload', // you can pass an id...
          container: document.getElementById('bg_container'), // ... or DOM Element itself
          url : "{{ url('/') }}/image-upload?_token="+$('meta[name="csrf-token"]').attr('content'),
          unique_names : false,
          max_file_count: 1,
          multi_selection: true,
          flash_swf_url : "{{ URL::asset('admin/js/pluploader/Moxie.swf') }}",
          silverlight_xap_url : "{{ URL::asset('admin/js/pluploader/Moxie.xap') }}",
          filters : {
              max_file_size : '60mb'
          },
          init: {
              FileUploaded: function (up, file) {
                  var upload_path = "{{ url('/uploads') }}";
                  var img = jQuery('&lt;img alt="click to change image" src="'+upload_path+file.name+'" style="width:auto; max-height:400px;"&gt;');
                  jQuery("#bg_upload").html(img);
              },
              FilesAdded: function(up, files) {
                  jQuery("#progress_file").css("display","block");
                  plupload.each(files, function(file) {
                      var img_type = file.name;
                      jQuery("#progress_file").append('&lt;div id="' + file.id + '" &gt;' + img_type + ' (' + plupload.formatSize(file.size) + ')&lt;b&gt;&lt;/b&gt;&lt;/div&gt;');
                  });
                  uploader.start();
              },
              UploadProgress: function(up, file) {
                  jQuery("#"+file.id).find("b").html('&lt;span&gt;' + file.percent + "%&lt;/span&gt;");
              },
              UploadComplete: function () {
                  jQuery("#progress_file").html("");
                  jQuery("#progress_file").css("display","none");
              },
              Error: function(up, err) {
                  console.log("\nError #" + err.code + ": " + err.message);
                  //document.getElementById('console').appendChild(document.createTextNode("\nError #" + err.code + ": " + err.message));
              }
          }
      });
      uploader.init();
  </code></pre>
  
  <p>Here is the route i defined:</p>
  
  <pre><code>Route::post('/image-upload', 'ProductsController@upload_image');
  </code></pre>
  
  <p>Here is the <code>upload_image</code> function of controller:</p>
  
  <pre><code>public function upload_image()
  {
      if( ! ini_get('date.timezone') )
      {
          date_default_timezone_set('GMT');
      }
      // Make sure file is not cached (as it happens for example on iOS devices)
      header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
      header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
      header("Cache-Control: no-store, no-cache, must-revalidate");
      header("Cache-Control: post-check=0, pre-check=0", false);
      header("Pragma: no-cache");
  
      /* 
      // Support CORS
      header("Access-Control-Allow-Origin: *");
      // other CORS headers if any...
      if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
              exit; // finish preflight CORS requests here
      }
      */
  
      // 5 minutes execution time
      @set_time_limit(5 * 60);
  
      // Uncomment this one to fake upload time
      // usleep(5000);
  
      // Settings
      $targetDir = base_path().'/uploads';
      $cleanupTargetDir = true; // Remove old files
      $maxFileAge = 5 * 3600; // Temp file age in seconds
  
      // Create target dir
      if (!file_exists($targetDir)) {
          @mkdir($targetDir);
      }
      //echo  $targetDir;
      // Get a file name
      if (isset($_REQUEST["name"])) {
              $fileName = $_REQUEST["name"];
      } elseif (!empty($_FILES)) {
              $fileName = $_FILES["file"]["name"];
      } else {
              $fileName = uniqid("file_");
      }
  
      $filePath = $targetDir . DIRECTORY_SEPARATOR . $fileName;
  
      // Chunking might be enabled
      $chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0;
      $chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 0;
  
  
      // Remove old temp files    
      if ($cleanupTargetDir) {
          if (!is_dir($targetDir) || !$dir = opendir($targetDir)) {
                  $data = '{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}';
          }
  
          while (($file = readdir($dir)) !== false) {
  
                  $tmpfilePath = $targetDir . DIRECTORY_SEPARATOR . $file;
  
                  // If temp file is current file proceed to the next
                  if ($tmpfilePath == "{$filePath}.part") {
  
                          continue;
                  }
  
                  // Remove temp file if it is older than the max age and is not the current file
                  if (preg_match('/\.part$/', $file) &amp;&amp; (filemtime($tmpfilePath) &lt; time() - $maxFileAge)) {
                          @unlink($tmpfilePath);
                  }
          }
          closedir($dir);
      }
  
  
      // Open temp file
      if (!$out = @fopen("{$filePath}.part", $chunks ? "ab" : "wb")) {
              $data = '{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}';
      }
      if (!empty($_FILES)) {
              if ($_FILES["file"]["error"] || !is_uploaded_file($_FILES["file"]["tmp_name"])) {
                      $data = '{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}';
              }
  
              // Read binary input stream and append it to temp file
              if (!$in = @fopen($_FILES["file"]["tmp_name"], "rb")) {
                      $data = '{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}';
              }
      } else {
              if (!$in = @fopen("php://input", "rb")) {
                      $data = '{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}';
              }
      }
  
      while ($buff = fread($in, 4096)) {
              fwrite($out, $buff);
      }
  
      @fclose($out);
      @fclose($in);
  
      // Check if file has been uploaded
      if (!$chunks || $chunk == $chunks - 1) {
              // Strip the temp .part suffix off
              rename("{$filePath}.part", $filePath);
      }
      $data = '{"jsonrpc" : "2.0", "result" : null, "id" : "id"}';
      return response()-&gt;json($data);
      //return '{"jsonrpc" : "2.0", "result" : null, "id" : "id"}';
  }
  </code></pre>
  
  <p>Can anyone tell me where i am wrong.</p>
  
  <p>Thanks in advance.</p>