Bel Posted January 9 Share Posted January 9 I did this code in HTML <label id="read" class="read" for="files">Choose:</label> <input type="file" accept="image/*|video/*" name="file" id="file" class="jump" multiple="true"> <input type="button" id="btlo" class="btload" name="load" value="Load" onclick="Load();"> and call function Load() below function Load(){ var fileInput = document.getElementById("file"); var str = new FormData(); for (i = 0; i < fileInput.files.length; i++) { str.append(fileInput.files.name, fileInput.files); } $.ajax({ url: "upload.php", method: "POST", data: str, contentType: false, cache: false, processData: false, beforeSend:function(){ $('#respimg').html("Sending..."); }, success:function(data){ $('#msgret').html(data); } }); } PHP <?php $num = 2; if (isset($_FILES['file'])){ for ($i = 0; $i < $num; $i++) { $nfile = $_FILES["file"]["name"][$i]; $tfile = $_FILES["file"]["size"][$i]; $ntemp = $_FILES["file"]["tmp_name"][$i]; } It isn´t work with o if isset but without it´s giving this mensage Notice: Undefined index: file Quote Link to comment https://forums.phpfreaks.com/topic/317615-upolad-file-php/ Share on other sites More sharing options...
kicken Posted January 9 Share Posted January 9 This: str.append(fileInput.files.name, fileInput.files); Should be this: str.append(fileInput.name, fileInput.files[i]); You want the name of the form field to used, and the value needs to be a single file not the whole collection. Lastly, your input needs to have the name: name="file[]" So that PHP will accept it as an array. Quote Link to comment https://forums.phpfreaks.com/topic/317615-upolad-file-php/#findComment-1614033 Share on other sites More sharing options...
Andou Posted January 9 Share Posted January 9 Also, while it doesn't affect readability (as far as I can read it, anyway), in the future you should probably use the Code button in the editor to show the code. It makes it easier to scroll down and see what's going on. Quote Link to comment https://forums.phpfreaks.com/topic/317615-upolad-file-php/#findComment-1614035 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.