Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Location
    Scotland
    Posts
    134
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Advice on multiple uploads into mysql

    Hi Guys,

    i have a page where users can select 1-5, this indicates how many files they want to upload, im used to just dealing with 1 upload at a time, i was wondering how i would go about inputting multiple entries into mysql also my input name will be different i take it aswell eh currently its:

    PHP Code:
         echo <form method="POST" action="uploadnzb.php">
               <
    p>
               <
    select name="uploadsneeded">
               <
    option value="1">1</option>
               <
    option value="2">2</option>
               <
    option value="3">3</option>
               <
    option value="4">4</option>
               <
    option value="5">5</option>
               </
    select><input type="submit" name="upsneeded" value="Upload!" /><br /><br /> 
    then the upload code part of:

    PHP Code:
    <?php  
                    
    ## how many files ########################################################
                    
    for($n=0$n $neededfiles$n++) { 
                                
                    echo 
    '<input type="hidden" name="need_1" value="'.$neededfiles1.'"><input type="file" name="files1"><br />';
                    
                    }                
    ?>
                    </td>
                    </tr>
                    <tr>
                    <td align="right" /><b>RAR/ZIP</b></td><td align="left">
    <?php

                    
    for($i=0$i $uploadsneeded$i++){

                    echo 
    '<input type="hidden" name="need_2" value="'.$uploadsneeded.'"><input type="file" name="files2" ><br />';

                    } 
    ?>
    depending on what the user select thats how many upload fields are displayed, would i need to loop them into mysql? not to sure what i need to do next lol

    thanks for nay help guys

    Graham

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    To make the upload fields you would do:
    PHP Code:
    for($n=0$n $neededfiles$n++)

        echo 
    '<input type="file" name="files' $n '"><br />';

    And on the page it's posted to you would loop through the files using foreach(), but make sure that only 5 files are uploaded total.
    PHP Code:
    // This is just an example
    $count 0;
    foreach(
    $_FILES as $file)
    {
        
    $count++;
        if(
    $count 5)
            break;

        
    // upload



  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •