Имам формуляр, който включва както изображенията, така и текста и всички тези данни трябва да бъдат вмъкнати в базата данни.
<form action="processupload.php" method="post" enctype="multipart/form-data" id="UploadForm">
<input name="name" type="text" />
<input name="age" type="text" />
<input name="fileToUpload" type="file" />
<input type="submit" id="SubmitButton" value="Upload" />
</form>
Въпреки това имам специално изискване, искам потребителят да може да попълни всички подробности, но когато стигне до частта за качване, искам изглед като този
където
- потребителят попълва текстовите полета
- избира изображение чрез бутона за качване
- получава визуализация на качено изображение (както е показано на фигурата)
- щракнете върху бутона за стартиране, лентата за напредъка ще започне до момента, в който изображението бъде качено
- след като горната стъпка бъде завършена, потребителят ще щракне върху главния бутон за изпращане и след това всички данни трябва да отидат в бекенда
Код за processupload.php
if (count ($_POST) > 1)
{
$name = $_POST['name'];
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
$new_filename = $target_dir . uniqid() . '.' . $imageFileType;
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $new_filename))
{
// do something
}
}
Скриптът, използван за товарач, е тук @fidlde. може ли някой да каже как мога да постигна тази функционалност
Скрипт
$(document).ready(function() {
var progressbox = $('#progressbox');
var progressbar = $('#progressbar');
var statustxt = $('#statustxt');
var submitbutton = $("#SubmitButton");
var myform = $("#UploadForm");
var output = $("#output");
var completed = '0%';
$(myform).ajaxForm({
beforeSend: function() { //brfore sending form
submitbutton.attr('disabled', ''); // disable upload button
statustxt.empty();
progressbox.slideDown(); //show progressbar
progressbar.width(completed); //initial value 0% of progressbar
statustxt.html(completed); //set status text
statustxt.css('color','#000'); //initial color of status text
},
uploadProgress: function(event, position, total, percentComplete) { //on progress
progressbar.width(percentComplete + '%') //update progressbar percent complete
statustxt.html(percentComplete + '%'); //update status text
if(percentComplete>50)
{
statustxt.css('color','#fff'); //change status text to white after 50%
}
},
complete: function(response) { // on complete
output.html(response.responseText); //update element with received data
myform.resetForm(); // reset form
submitbutton.removeAttr('disabled'); //enable submit button
progressbox.slideUp(); // hide progressbar
}
});
});