Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to upload multiple files using Jquery

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 477
    Comment on it

    Hello Reader's!. Now multiple files on a single getting in fashion so you can use any of the multiple upload library code, But here we'll see how to use Jquery and PHP to do the same For getting it start we need a html form page and it'll go like this:-

    Ajax upload form

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
    
        function sendfile(){
            var fd = new FormData();  
    
            for (var i = 0, len = document.getElementById('myfile').files.length; i < len; i++) {
                fd.append("myfile", document.getElementById('myfile').files[i]);                
            }
    
            $.ajax({
              url: 'uploadfile.php',
              data: fd,
              processData: false,
              contentType: false,
              type: 'POST',      
              success: function(data){
                alert(data);
              }
            });         
        }
      </script>
    
    </head>
    <body>
        <form action="uploadfile.php" method="post" enctype="multipart/form-data" id="form-id">
    
        <p><input id="myfile" type="file" name="myfile" multiple=multiple/>
        <input type="button" name="upload" id="upload" value="Upload" onclick="sendfile()" id="upload-button-id"  /></p>
        </form>
    </body>
    </html>
    

    In the above code you can see the google ajax libraries are included Now create an uploadfile.php file file and put the code below:-

    <?php
    
        $uplolad = "targetFolder/"; 
        //for($i=0; $i <count($_FILES['myfile']['name']); $i++){
            if(move_uploaded_file($_FILES['myfile']['tmp_name'], $upload.$_FILES['myfile']['name'])) { 
                echo 'item upload to target folder'; 
    
            }else{       
                echo 'Not Upload '; //in case of any error, fail
            }   
        }// 
    
    ?>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: