I am creating a website, in users pages, I just wanted to add avatar (image), hence used Dropzone >> js and css.
In my case, the PHP script moved the uploaded image into a folder successfully (without any error), but the image name is not inserted (updated) into my db table.
The user
table has an avatar field for storage of the image name. If anyone can help, is really there error in below code or ....
uploads.php
include ('../fonfig/connection.php');
$ds = DIRECTORY_SEPARATOR;
$id = $_GET['id'];
$storeFolder = 'uploads';
$ext = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
$newname = time();
$dandom = rand(100, 999);
$name = $newname.$random.'.'.$ext;
$query= "UPDATE users SET avatar = '$name' WHERE id=$id";
$res = mysqli_query($dbc, $query);
echo $query.'<br/>';
echo mysqli_error($dbc);
if (!empty($_FILES)) {
$tempFile = $_FILES['file']['tmp_name'];
$targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds;
$targetFile = $targetPath. $name;
move_uploaded_file($tempFile,$targetFile);
}
?>
users.php
<script>
$(document).ready(fucntion(){
Dropzone.autoDiscover = false;
var myDropzone = new Dropzone("#avatar-dropzone");
});
</script>
<form action="uploads.php?id=<?php echo $opened['id']; ?>" class="dropzone" id="avatar-dropzone">
<input type="file" name="file"/>
</form>