С этим решением вы можете загрузить более одного пути к файлу в mysql и и фотографии в папки, используя одну форму, трюк, который я использовал, это FormData
для загрузки файла и String (текст) тоже.
Сначала Id дал свою форму id
, затем я сослался на Id в файле Jquery, чтобы использовать его в данных формы.
HTML код:
................
<form role="form" action=""
method="post" autocomplete="off" class="form"
enctype="multipart/form-data" id="myform" >
<div class="form-group">
<label class="" for="">Ministry in the
church(facultative)</label>
<input type="text" name="mn_church" placeholder="Facultative" class="form-control" id="mn_church">
</div>
</fieldset>
<!-- end -->
<!-- Attachements -->
<fieldset>
<h4>Document attachments:</h4><br>
<div class="form-group">
<label class="" for="">Last degree obtained</label>
<input type="file" name="ldgree" placeholder="Upload" class=" form-control" id="ldgree">
</div>
<button type="button" class="btn btn-previous">Previous</button>
<button type="button" onclick="insertDataThirdStep() " class="btn btn-next">Next</button>
</div>
</fieldset>
.............
Я переформатировал свой php-код следующим образом:
$mn_church = trim($_POST['mn_church']);
$mn_church = strip_tags($mn_church);
$mn_church = htmlspecialchars($mn_church);
$fileName = rand(0000,9999).'_'.$_FILES['ldgree']['name'];
$sourcePath = $_FILES['ldgree']['tmp_name'];
$targetPath = "images/fuploads/".$fileName;
if(move_uploaded_file($sourcePath,$targetPath)){
$uploadedFile = $fileName;
}
$query = "
UPDATE
aku_student_application
SET
mychurch ='$mn_church',
last_degree_optained='$targetPath' "
Jquery код для работы с php
function insertDataFourthStep() {
var form = document.getElementById('myform');
var church _Input = document.getElementById('mn_church');
var Lastdgree_Input = document.getElementById('ldgree').files[0];
var mn_church= new FormData(form);
var ldgree = new FormData(form);
student_id.append("mn_church",church _Input);
ldgree.append("file",Lastdgree_Input);
$.ajax({
type: 'POST',
url: 'step-4-appli-form-attachments.php',
data:ldgree,mn_church,
contentType: false,
cache: false,
processData:false,
success: function(data){
console.log('Success fourth step');
// clear file field
// $("#ldgree").val("");
}
});
}
Спасибо друзьям за положительные отзывы