Advertisement
arijulianto

PHP jQuery Auto Add File & Multiple Upload

Aug 19th, 2014
461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.27 KB | None | 0 0
  1. <style>
  2. a,a:visited{cursor:pointer;color:#0000ff}
  3. </style>
  4. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
  5. <script>
  6. $(function(){
  7. $('.pick-file').live('change',function(){
  8.     var row = '<div class="file">'+$('.list-file').find('.file:first').html()+'</div>';
  9.     $('.list-file').append(row);
  10.     $(this).parent().append('<a class="rem">[x] Hapus</a>');
  11.     $('.list-file').find('.file:last').find('.rem').remove();
  12. });
  13. $('.rem').live('click',function(){
  14.     var tanya = confirm('Anda yakin ingin menghapus item ini?');
  15.     if(tanya)
  16.         $(this).parent().remove();
  17. });
  18. })
  19. </script>
  20.  
  21. <div class="workspace">
  22. <form action="" method="post" enctype="multipart/form-data">
  23. <?php
  24. $dir = 'upload/';
  25. if(isset($_POST['save'])){
  26.     foreach($_FILES['img']['name'] as $i=>$img){
  27.         if($_FILES['img']['size'][$i]>0){
  28.             $upload = move_uploaded_file($_FILES['img']['tmp_name'][$i], $dir.$img);
  29.             if($upload) $status = $status+1;
  30.         }
  31.     }
  32.     if($status>0){
  33.         echo "<p>$status image berhasil diupload...</p>";
  34.     }else{
  35.         echo "<p>File aggal diupload...</p>";
  36.     }
  37. }
  38. ?>
  39. <div class="list-file">
  40. <div class="file"><input class="pick-file" type="file" name="img[]" accept="image/*" /></div>
  41. </div>
  42. <input type="submit" name="save" value="Upload" />
  43. </form>
  44. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement