php - How to detect the number of uploaded files and their names before uploading from client side by javascript or jquery? -
i want upload multiple files , have file called test.php code:
<!doctype html> <html> <head> <meta charset="utf-8"> <script src="js/jquery-1.8.0.min.js"></script> <script> $(function(){ var myvar; $('form').submit(function(){ myvar = setinterval(ajax, 1000); }); var ajax = function() { $.ajax({ url: 'test2.php', type: 'post', success: function(ajax_result){ $('.result').html(ajax_result); if (!ajax_result) { clearinterval(myvar); } }, error: function(){ alert('error'); } }); }; }); </script> </head> <body style="width:100%; height:100%;"> <form action="test2.php" target="iframe" method="post" enctype="multipart/form-data" > <input type="hidden" name="<?php echo ini_get("session.upload_progress.name"); ?>" value="fil" /> <input name="file[]" type="file" multiple /> <input type="submit"> </form> <iframe id="iframe" name="iframe"></iframe> <div class="result" style="width:100%; height:100%;"></div> </body> </html> and file called test2.php code:
<?php session_start(); if (isset($_files['file'])){ ($i = 0; $i < count($_files['file']['tmp_name']); $i++) { move_uploaded_file($_files['file']['tmp_name'][$i],'a/'.$_files['file']['name'][$i]); } } if (isset($_session[$key = ini_get("session.upload_progress.prefix") . 'fil'])) { var_dump($_session[$key]); } else echo false; ?> now want before sending files server detect number of files selected via names in client side.
how can this?
$('form').submit(function() { var numberoffilesabouttobesubmitted = $("[name='file[]']", ).prop("files").length; });
note not submitting files ajax request, has no association form @ all.
also note doesn't work in ie < 10
Comments
Post a Comment