0

How to upload files from this form to the form that sends the message. Currently, the message is being sent, but no files I can't pass values from JS to a form in

My website: https://fck-auto.de/ankaufahrzeuge/

FORM: https://jsfiddle.net/alexjamesbrown/2nzL9f7g/

PHP CODE:

if(count($_FILES['upload']['name']) > 0){

    $rand = rand();

    $createFolder = uniqid();
    mkdir('uploads/'.$createFolder);

    for($i=0; $i<count($_FILES['upload']['name']); $i++) {

        $tmpFilePath = $_FILES['upload']['tmp_name'][$i];

        if($tmpFilePath != ""){

            $shortname = $_FILES['upload']['name'][$i];
            $explode = explode(".", $_FILES['upload']['name'][$i]);
            $filePath = "uploads/".$createFolder. '/' . rand().'.'.$explode[1];

            if(move_uploaded_file($tmpFilePath, $filePath)) {
                $files[] = $shortname;

            }
        }
    }

}

1 Answers1

0

Check you have enctype="multipart/form-data" in your form.

Ex :

<form action="#" method="post" enctype="multipart/form-data">

If you submit using AJAX refer

Uploading both data and files in one form using Ajax?

Sajeewa
  • 74
  • 1
  • 13