Skip to main content
<?php
define('ROOTPATH', dirname(__DIR__) . '\\upload\\');
$result = '';
$property_images = $_FILES['fileToUpload']['name'];
if (!empty($property_images)) {
    for ($up = 0; $up < count($property_images); $up++) {
        if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'][$up], ROOTPATH . $_FILES['fileToUpload']['name'][$up])) {
            echo $result = "OK";
        }
    }
} else {
    echo $result = "Nada";
}
?>

define('ROOTPATH', dirname(DIR) . '\upload\'); $result = ''; $property_images = $_FILES['fileToUpload']['name']; if (!empty($property_images)) { for ($up = 0; $up < count($property_images); $up++) { if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'][$up], ROOTPATH . $_FILES['fileToUpload']['name'][$up])) { echo $result = "OK"; } } } else { echo $result = "Nada"; } ?>

<?php

define('ROOTPATH', dirname(DIR) . '\upload\'); $result = ''; $property_images = $_FILES['fileToUpload']['name']; if (!empty($property_images)) { for ($up = 0; $up < count($property_images); $up++) { if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'][$up], ROOTPATH . $_FILES['fileToUpload']['name'][$up])) { echo $result = "OK"; } } } else { echo $result = "Nada"; } ?>

<?php
define('ROOTPATH', dirname(__DIR__) . '\\upload\\');
$result = '';
$property_images = $_FILES['fileToUpload']['name'];
if (!empty($property_images)) {
    for ($up = 0; $up < count($property_images); $up++) {
        if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'][$up], ROOTPATH . $_FILES['fileToUpload']['name'][$up])) {
            echo $result = "OK";
        }
    }
} else {
    echo $result = "Nada";
}
?>
Fonte Link

HTML - index.html

 <div>
        <form method="post" enctype="multipart/form-data">
            Selecione um ficheiro:
            <input type="file" name="fileToUpload[]" multiple accept="application/pdf">
            <input type="submit" value="Upload Image" name="submit" id="myFile" >
        </form>
    </div>   

Javascript

$(document).ready(function () {//
           $("form").submit(function(evt){
               var formData = new FormData($(this)[0]);
                $.ajax({
                    url: 'php/upload.php',
                    type: 'post',
                    data: formData,
                    contentType: false,
                    cache: false,
                    processData: false,                        
                    success: function (result) {
                        alert('Result: ' + result);
                    }
                });

            });

PHP

<?php

define('ROOTPATH', dirname(DIR) . '\upload\'); $result = ''; $property_images = $_FILES['fileToUpload']['name']; if (!empty($property_images)) { for ($up = 0; $up < count($property_images); $up++) { if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'][$up], ROOTPATH . $_FILES['fileToUpload']['name'][$up])) { echo $result = "OK"; } } } else { echo $result = "Nada"; } ?>