Answer the question
In order to leave comments, you need to log in
Duplicate uploaded file from dropzone or send again?
There are js dropzones, but no backend, but xhr is sent, the image is displayed as a preview.
Hung up id on input, does not react in any way to change, also tried through formdata - it displays empty data. Nothing is left in $_POST, or as now I get "Cannot read properties of undefined (reading '0')"
<form action="#" class="dropzone" id="js-form" enctype="multipart/form-data" method="POST">
<div class="fallback">
<input name="file" id="js-file" type="file"
>
</div>
<div class="dz-message needsclick"><center>
<div class="mb-3">
<i class="display-4 text-muted bx
bx-cloud-upload"></i>
</div>
<h5>Перетащите или выберите для загрузки.</h5></center>
</div>
</form>
</div>
<div class="text-center mt-4">
<button type="button" name="submit" id="upload_start_btn" class="btn btn-primary
waves-effect waves-light">Загрузить</button>
</div>
<script>
Dropzone.autoDiscover = false;
$(document).ready(function () {
$(".dropzone").dropzone();
});
</script>
<script>
$('#upload_start_btn').on('click', function() {
var file_data = $('#js-file').prop('files')[0];
var form_data = new FormData();
form_data.append('file', file_data);
alert(form_data);
$.ajax({
url: 'ajax/file.php',
dataType: 'text',
cache: false,
contentType: false,
processData: false,
data: form_data,
type: 'post',
success: function(php_script_response){
alert(php_script_response);
}
});
});
<?php
if ( 0 < $_FILES['file']['error'] ) {
echo 'Error: ' . $_FILES['file']['error'] . '<br>';
}
else {
move_uploaded_file($_FILES['file']['tmp_name'], 'uploads/' . $_FILES['file']['name']);
}
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question