title: jQuery and php file upload
body: <p>I do not understand, and google does not give me the answer. I want to upload a file and the results show in the div without page relode, but I can not get it!!!!</p>
  
  <p>html:</p>
  
  
  
  <pre><code>&lt;form method="post" action="process/pic2.php" enctype="multipart/form-data" id="userpic"&gt;
  &lt;p&gt;Izvēlies bildi: &lt;input type="file" name="img_to_upload" /&gt;&lt;input type="submit" name="upload" value="Augšupielādēt" /&gt;&lt;/p&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>jquery:</p>
  
  <pre><code>jQuery(function(){
          jQuery('#userpic').submit(function(){
              jQuery.ajax({
                  type: 'POST',
                  enctype: 'multipart/form-data',
                  url: jQuery('#userpic').attr('action'),
                  data: jQuery('#userpic').serialize(),
                  success: function(data){
                      if(data){
                          jQuery('#picinfo').html(data);
                      }else{
                          jQuery('#uerpic').fadeOut(500);
                          jQuery('#picinfo').html('&lt;center&gt;&lt;img src="img/loader.gif" /&gt;&lt;/center&gt;');
                              window.location = 'index.php';
                      }
                  }
              });
              return false;
          });
      });
  </code></pre>
  
  <p>and my php:</p>
  
  <pre><code>if(isset($_FILES['img_to_upload']['name']) &amp;&amp; !empty($_FILES['img_to_upload']['name'])){
          echo 'Done!';
      }else{
          echo 'Error!';
      }
  </code></pre>
  
  <p>all the time showing the "error" text..</p>
  
  <p>P.S. Sorry for bad English.</p>