Edit: Also I want to add, I get no errors whatsoever either in js, or PHP.
Technically, am using a form where I want the seller to fill up the necessary stuff of a product, also including the Image of the product to show in the Shopping area. I hate the default input type file of html5, and I have a hard time hiding it, so I came across with dropzone. Now dropzone kinda works on the client side, but doesn't seem to be working on the Server side. No file gets uploaded on the redirect I want it to be sent.
This is kind of a new thing to me, so I'm lost on what to do.
this is the html code
<form enctype='multipart/form-data' action='upload.php' method='POST'>
<div class='form-group'>
<input class='form-control' type='text' placeholder='Title' id='titleInput' name='titleInput'>
</div>
<div class='form-group'>
<input class='form-control' type='number' placeholder='Price' id='priceInput' name='priceInput'>
</div>
<div class='dropzone' id='myDropzone'>
</div>
<button id='submit-all' type='submit' name='Post'>Submit<\button>
</form>
the javascript code
Dropzone.options.myDropzone= {
url: 'upload.php',
paramName: "file",
autoProcessQueue: false,
uploadMultiple: false,
//parallelUploads: 5,
//maxFiles: 5,
maxFilesize: 1,
acceptedFiles: 'image/*',
addRemoveLinks: true,
init: function() {
dzClosure = this; // Makes sure that 'this' is understood inside the functions below.
// for Dropzone to process the queue (instead of default form behavior):
document.getElementById("submit-all").addEventListener("click", function(e) {
// Make sure that the form isn't actually being sent.
//e.preventDefault();
e.stopPropagation();
dzClosure.processQueue();
});
//send all the form data along with the files:
this.on("sendingmultiple", function(data, xhr, formData) {
formData.append("titleInput", jQuery("#titleInput").val());
formData.append("priceInput", jQuery("#priceInput").val());
});
}
}
And the upload.php code
<?php
if(isset($_POST['Post'])){
if(isset($_FILES['file']['name'])){
$imageName = $_FILES['file']['name'];
$imageNameTemp = $_FILES['file']['tmp_name'];
echo $imageName;
}
else{
$imageName = "";
echo "null";
}
$errorMessage = "";
if($imageName != "") {
$targetDir = "assets/images/productImages/";
$imageName = $targetDir . uniqid() . basename($imageName);
$imageFileType = pathinfo($imageName, PATHINFO_EXTENSION);
if($_FILES['file']['size'] > 5000000) {
$errorMessage = "Sorry your file is too big!";
$uploadOk = 0;
}
if(strtolower($imageFileType) != "jpeg" && strtolower($imageFileType) != "png" && strtolower($imageFileType) != "jpg") {
$errorMessage = "Sorry, only jpeg, jpg and png files are allowed";
$uploadOk = 0;
}
if(strtolower($imageFileType) == "jpeg" || "jpg"){
$src = imagecreatefromjpeg($imageNameTemp);
}
if(strtolower($imageFileType) == "png"){
$src = imagecreatefrompng($imageNameTemp);
}
if($uploadOk == 1) {
list($width_min, $height_min) = getimagesize($imageNameTemp);
if($width_min > 1920){
$newwidth_min = 1920;
$newheight_min = ($height_min / $width_min) * $newwidth_min;
}
else if($height_min > 1920){
$newheight_min = 1920;
$newwidth_min = ($height_min / $width_min) * $newheight_min;
}
else{
$newheight_min = $height_min;
$newwidth_min = $width_min;
}
$tmp_min = imagecreatetruecolor($newwidth_min, $newheight_min);
imagecopyresampled($tmp_min, $src, 0, 0, 0, 0, $newwidth_min, $newheight_min, $width_min, $height_min);
imagejpeg($tmp_min, $imageName);
$uploadOk = 1;
}
else {
//image did not upload
$uploadOk = 0;
}
}
}
?>
So, when it redirects to upload.php, it echoes null because that what i wrote, if no file is sent.
Please help