Skip to main content
Participating Frequently
April 22, 2020
Question

multiple file upload controls for uploading to different locations PHP

  • April 22, 2020
  • 1 reply
  • 531 views

Hi,

I'm having an issue with inserting data into a table "property" I need to upload a few documents to a document folder on the server in two different locations but I am unsure how to do it with DW.

I have seen some example scripts but they don't seem to do what I need.

 

My form input is:

<input type="file" name="epccert" id="epccert">

And

<input type="file" name="agree1" id="agree1">

They are all named differently.

I'm using the Insert Record server behaviour and not sure where to enter the script to give the upload locations.

The scripts I have seen would need to be added over 10 times for each of my elements which seems a little silly.

Is there an easy way to do this?

 

Thanks in advance

    This topic has been closed for replies.

    1 reply

    Legend
    April 22, 2020

    See if the below helps:

    https://makitweb.com/multiple-files-upload-at-once-with-php/

     

    Edited. The above will give you a basic upload however if you want to upload the files to 2 different folders on the server then alter the php script as below:

     

    <?php
    if(isset($_POST['submit'])){

    // Count total files
    $countfiles = count($_FILES['file']['name']);

     

    // Looping all files

    for($i=0;$i<$countfiles;$i++){
    $filename = $_FILES['file']['name'][$i];
    $folder_1 = 'uploads_1/' . $filename;
    $folder_2 = 'uploads_2/' . $filename;

    // Upload file
    move_uploaded_file($_FILES['file']['tmp_name'][$i], $folder_1);
    copy($folder_1, $folder_2);
    }

    }
    ?>

     

     

    Of course this is as basic as it gets. You'd probably want to do a check as to which file extensions are allowed to be uploaded, max-size allowed etc.

    Participating Frequently
    April 22, 2020

    Thank you so much for taking the time to reply to my post.

    I will try this now.

    Thanks again!