I'm having a problem with dropzone and the upload.php file. I'm trying to save the files that are uploaded in a directory on my computer. I'm working with MAMP, so the directory is inside the htdocs. The code for my form is:
<form action="./upload.php" class="dropzone" id="upload-form" method="post" enctype="multipart/form-data">
<div class="fallback">
<input id="upload" name="upload[]" type="file" multiple/>
</div>
<input type="submit" name="uploaden[]" id="uploaden" multiple/>
</form>
My dropzone initialisation:
Dropzone.autoDiscover = false;
$myDropzone = new Dropzone('#upload-form', {
url: "/upload.php",
uploadMultiple: true,
addRemoveLinks: true,
maxFiles: 25,
accept: function(file, done) {
console.log("uploaded");
done();
},
init: function() {
this.on("addedfile", function() {
if (this.files[25]!=null){
this.removeFile(this.files[0]);
}
});
var submitButton = document.querySelector("#uploaden")
myDropzone = this; // closure
submitButton.addEventListener("click", function() {
myDropzone.processQueue();
});
}
});
and my NEW upload.php file:
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
$ds = DIRECTORY_SEPARATOR; //1
$storeFolder = '/uploads'; //2
if (!empty($_FILES)) {
if(isset($_FILES['files']['tmp_name']) && is_array($_FILES['files']['tmp_name'])){
foreach($_FILES["files"]["tmp_name"] as $key=>$tmp_name) {
$tempFile = $_FILES['file']['tmp_name']; //3
$targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds; //4
if(!file_exists($targetPath)) {
$targetFile = $targetPath. $_FILES['file']['name']; //5
move_uploaded_file($tempFile,$targetFile); //6
}
else {
$targetFile = $targetPath. $_FILES['file']['name']; //5
move_uploaded_file($tempFile,$targetFile); //6
}
}
}
}
?>
I really don't know what I'm doing wrong. At first I got the following errors, but now those aren't even showing anymore..
[18-May-2015 12:12:31 Europe/Amsterdam] PHP Notice: Array to string conversion in /Users/anoukkolkman/Desktop/School/Afstuderen/Website/htdocs/upload.php on line 17
[18-May-2015 12:12:31 Europe/Amsterdam] PHP Warning: move_uploaded_file() expects parameter 1 to be string, array given in /Users/anoukkolkman/Desktop/School/Afstuderen/Website/htdocs/upload.php on line 19
Those lines are:
$targetFile = $targetPath. $_FILES['file']['name']; //5
move_uploaded_file($tempFile,$targetFile); //6
Can somebody help me what I'm doing wrong and why the files aren't places in the directory?