title: Redirect in Plupload
body: <p>Wonder if someone can advise please - I am using Plupload and need to redirect to a different page to add information into a database. </p>
  
  <p>I can upload the file perfectly, but I cannot seem to get it to redirect.</p>
  
  <p>Ive tried putting in the code into "UploadComplete" and in a different test into "FileUploaded"</p>
  
  <p>Using Firebug I put in breaks into the script and both sections are stopped at at the start, but when the file is finished it doesnt touch either of them.  </p>
  
  <p>Therefore I thought Id put it into the upload.php file in the Chunks section (as per a google result suggested).  </p>
  
  <pre><code>// Check if file has been uploaded
  if (!$chunks || $chunk == $chunks - 1) {
  // Strip the temp .part suffix off 
  rename("{$filePath}.part", $filePath);
  $mypi = $projid;
  header("Location: addimg.php?file=" . $fileName . "&amp;blid=" . $mypi);
  die();
  }
  </code></pre>
  
  <p>In debugging it went through and hit the redirect and the die following, then then it went back to the start of the "if (!chunks etc)" and run through it again, but never redirected.  </p>
  
  <p>What am I missing please!  Im pulling out my hair to make this work. </p>
  
  <p>Thanks in advance</p>
  
  <p>Javascript:</p>
  
  <pre><code>var uploader = new plupload.Uploader({
  browse_button: 'browse', // this can be an id of a DOM element or the DOM element itself
  container: document.getElementById('upcontainer'), // ... or DOM Element itself
  
  //url: 'upload.php',
   url: 'uploader_plup/upload.php?wts=&lt;?php echo $projid;?&gt;',
  
  chunk_size: '2mb',
  
  max_retries: '5',      
  
  // Sort files
  sortable: true,
  
  // Specify what files to browse for
      filters : {
          mime_types:[
          {title : "Image files", extensions : "jpg,gif,png"},
          {title : "Zip files", extensions : "zip"},
          {title : "Video files", extensions : "mov,mp4,mpeg,avi,mpg,wmv,w4v,flv,ogv,divx,asf,asx,ram,m2v"},                                                      
          {title : "PDF files", extensions : "pdf"},                                 
          {title : "Text files", extensions : "htm,html,doc,txt,rtf,ppt"}
      ],},
  }
  );
  
  uploader.init();
  
  
  
  uploader.bind('FilesAdded', function(up, files) {
  var html = '';
  plupload.each(files, function(file) {
      html += '&lt;li id="' + file.id + '"&gt;' + file.name + '     ('+plupload.formatSize(file.size) + ') &lt;b&gt;&lt;/b&gt;&lt;/li&gt;';
  });
  document.getElementById('filelist').innerHTML += html;
  });
  
  uploader.bind('FileUploaded', function(up, file, info) {
              // Called when file has finished uploading
              log('[FileUploaded] File:', file, "Info:", info);
          }); 
  
  uploader.bind('ChunkUploaded', function(up, file, info) {
     // Called when file chunk has finished uploading
    log('[ChunkUploaded] File:', file, "Info:", info);
  });
  
  uploader.bind('UploadProgress', function(up, file) {
  document.getElementById(file.id).getElementsByTagName('b')[0].innerHTML = '&lt;span&gt;' + file.percent + "%&lt;/span&gt;";
  log('[UploadProgress] File:', file, "Info:", info);
  });
  
  uploader.bind('UploadComplete', function(up, files) {
              // Called when file has finished uploading 
              // console.log("[UploadComplete]");
              // backButtonState = true;
              var totup = uploader.total.uploaded + 1;
              var fillen =  uploader.files.length;
               if(totup == fillen)
              {
                  var mypi = "&lt;?php  echo $projid; ?&gt;";
                  window.location = "addimg.php?file="+files+"&amp;blid="+mypi;   
              }
             log('[UploadComplete]');   
  
          });
  
  uploader.bind('Error', function(up, err) {
  document.getElementById('console').innerHTML += "\nError #" + err.code +   ": " + err.message;
  log('[Error] File:', file, "Info:", err.message);
  });
  
  document.getElementById('start-upload').onclick = function() {
  uploader.start();       
  };
  
  function log() {
      var str = "";
  
      plupload.each(arguments, function(arg) {
          var row = "";
  
          if (typeof(arg) != "string") {
              plupload.each(arg, function(value, key) {
                  // Convert items in File objects to human readable form
                  if (arg instanceof plupload.File) {
                      // Convert status to human readable
                      switch (value) {
                          case plupload.QUEUED:
                              value = 'QUEUED';
                              break;
  
                          case plupload.UPLOADING:
                              value = 'UPLOADING';
                              break;
  
                          case plupload.FAILED:
                              value = 'FAILED';
                              break;
  
                          case plupload.DONE:
                              value = 'DONE';
                              break;
                      }
                  }
  
                  if (typeof(value) != "function") {
                      row += (row ? ', ' : '') + key + '=' + value;
                  }
              });
  
              str += row + " ";
          } else {
              str += arg + " ";
          }
      });
  
      var log = document.getElementById('console');
      log.innerHTML += str + "\n";
  }
  
  
  &lt;/script&gt; 
  </code></pre>