Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. <form enctype="multipart/form-data" method="post">
  2. <input name="files[]" type="file" id="upload_file" /><br/>
  3. <input type="button" id="upload" value="Upload File" />
  4. </form>
  5.  
  6. $("#upload_file").hide();
  7. $("#upload").click(function() {
  8. $("#upload_file").click();
  9. })
  10.  
  11. $('#upload_file').change(function(e) {
  12. e.preventDefault();
  13. var formData = new FormData($(this).parents('form')[0]);
  14.  
  15. $.ajax({
  16. url: '___ajax_upload_files.php',
  17. type: 'POST',
  18. xhr: function() {
  19. var myXhr = $.ajaxSettings.xhr();
  20. return myXhr;
  21. },
  22. success: function (data) {
  23.  
  24. $('#upload_span').html( data );
  25. },
  26. data: formData,
  27. cache: false,
  28. contentType: false,
  29. processData: false
  30. });
  31. return false;
  32. })
  33.  
  34. if ( !empty( $_FILES['files']['name'] ) ) {
  35. $target_path = '../images/';
  36. $ext = explode('.', basename( $_FILES['files']['name'] ) );
  37. $target_path = $target_path . md5(uniqid()) . "." . $ext[count($ext)-1];
  38. $val_img = substr( $target_path , 10 );
  39.  
  40. //Here code to display uploaded image
  41.  
  42. if(move_uploaded_file($_FILES['files']['tmp_name'][$i], $target_path)) {
  43. echo '<a href=""><img src="../images/'. $val_img. '" ></a> ';
  44. }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement