Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 24th, 2012  |  syntax: None  |  size: 1.19 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. File upload in php Ajax jQuery not working
  2. <table>
  3.     <form name="profileimage" id="profileimage" method="post"  enctype="multipart/form-data" >
  4.         <tr>
  5.             <td><img id="partner_pic" src="" height="100" width="100" /></td>
  6.         </tr>
  7.         <tr>
  8.             <td><input type="file" name="fileimg1" id="fileimg1" /></td>
  9.         </tr>
  10.         <tr>
  11.             <td><p id="pic_profile_p"></p></td>
  12.         </tr>
  13.         <tr>
  14.             <td><input type="submit" name="uploadimg" value="Change Picture" /></td>
  15.         </tr>
  16.     </form>
  17.  
  18. </table>
  19.        
  20. <?php
  21.      $target = "upload/";
  22.      $target = $target . $_FILES['fileimg1']['name'] ;
  23.      $ok=1;
  24.      if(move_uploaded_file($_FILES['fileimg1']['tmp_name'], $target))
  25.      {
  26.          echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
  27.      }
  28.      else {
  29.          echo "Sorry, there was a problem uploading your file. <br />" . $_FILES['fileimg1']['error'];
  30.  
  31.      }
  32. ?>
  33.        
  34. $("#profileimage").submit(function(){
  35.  
  36.         var data = $(this).serialize();
  37.         $.post('ajx_upload.php', data, function(return_data){
  38.             $('#pic_profile_p').html(return_data)
  39.         });
  40.  
  41.  
  42.         return false;
  43.     });