Jump to content

Upolad File PHP


Recommended Posts

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);
               url: "upload.php",
               method: "POST",
               data: str,               
               contentType: false,
               cache: false,
               processData: false,  


$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

Link to comment
Share on other sites


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:


So that PHP will accept it as an array.


Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.