It is not possible to send files to the server along with other data.
HTML:
<input type="file" id='my_file' name="my_file[]" accept='image/*' multiple> JS Code:
// var data = new FormData(); var fp = $("#my_file"); var id= // some value for(var i=0, len=fp[0].files.length; i<len; i++) data.append('my_file[]', fp[0].files[i]); var xmlhttp = getXmlHttp(); xmlhttp.open('POST', '/or/save.php', true); xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xmlhttp.send("id=" + id + "&" + "data=" + data); On the server in save.php I check with print_r($FİLES) . The problem is in the code, on the server all the rules. Where is the mistake?
The following code works, but it is without ajax
<form method="post" enctype="multipart/form-data" accept='\image'> <input type="file" name="my_file[]" multiple> <input type="submit" value="Upload"> </form> <?php if (isset($_FILES['my_file'])) { $myFile = $_FILES['my_file']; $fileCount = count($myFile["name"]); echo print_r($_FILES); for ($i = 0; $i < $fileCount; $i++) { ?> <p>File #<?= $i+1 ?>:</p> <p> Name: <?= $myFile["name"][$i] ?><br> Temporary file: <?= $myFile["tmp_name"][$i] ?><br> Type: <?= $myFile["type"][$i] ?><br> Size: <?= $myFile["size"][$i] ?><br> Error: <?= $myFile["error"][$i] ?><br> </p> <?php } } ?>