Witajcie, mam problem, którego nie potrafię rozwiązać. Wygląda to tak, że mam formularz w html, który jest wysyłany postem. W nim są wysyłanie różne inputy tekstowe ALE również zdjęcia.
Formularz musi pokazywać wybrane zdjęcia, mieć możliwość usunięcia i dogrania.
Pod linkiem możecie zobaczyć jak to wygląda i działa:
https://fck-auto.de/ankaufahrzeuge/Formularz generuje zdjęcia w generowanych folderach, bo klient chciał mieć generowaną galerie z załączników do każdego maila... W mailu przychodzą dane z inputów i link do galerii.
Nie potrafię przekazać zdjęć z skryptu js do php. Patrzę na ten kod i już nie ogarniam.
KOD PONIŻEJ:
CZĘŚĆ FORMULARZA
<form id="contact" action="../form/sendmemail.php" method="post" enctype="multipart/form-data">
<span>Dodaj zdjęcia (max 20 sztuk na jeden raz) *
</span> <div class="files" id="files1"> <input type="file" name="upload[]" multiple="multiple" enctype="multipart/form-data" /> <ul class="fileList"></ul>
<a href="https://fck-auto.de/ankaufahrzeuge/foto/">Zobacz jak powinny wyglądać zdjęcia do wyceny
</a>
FORMULARZ POZWALA DODAWAĆ I USUWAĆ PLIKI PRZED PRZESŁANIEM:
$.fn.fileUploader = function (filesToUpload, sectionIdentifier) {
var fileIdCounter = 0;
this.closest(".files").change(function (evt) {
var output = [];
for (var i = 0; i < evt.target.files.length; i++) {
fileIdCounter++;
var file = evt.target.files[i];
var fileId = sectionIdentifier + fileIdCounter;
filesToUpload.push({
id: fileId,
file: file
});
var removeLink = "<a class=\"removeFile\" href=\"#\" data-fileid=\"" + fileId + "\">Remove
</a>";
output.push("
<li><strong>", escape(file.name), "
</strong> - ", file.size, " bytes.
", removeLink, "
</li> ");
};
$(this).children(".fileList")
.append(output.join(""));
//reset the input to null - nice little chrome bug!
evt.target.value = null;
});
$(this).on("click", ".removeFile", function (e) {
e.preventDefault();
var fileId = $(this).parent().children("a").data("fileid");
// loop through the files array and check if the name of that file matches FileName
// and get the index of the match
for (var i = 0; i < filesToUpload.length; ++i) {
if (filesToUpload[i].id === fileId)
filesToUpload.splice(i, 1);
}
$(this).parent().remove();
});
this.clear = function () {
for (var i = 0; i < filesToUpload.length; ++i) {
if (filesToUpload[i].id.indexOf(sectionIdentifier) >= 0)
filesToUpload.splice(i, 1);
}
$(this).children(".fileList").empty();
}
return this;
};
(function () {
var filesToUpload = [];
var files1Uploader = $("#files1").fileUploader(filesToUpload, "files1");
$("#uploadBtn").click(function (e) {
e.preventDefault();
var formData = new FormData();
for (var i = 0, len = filesToUpload.length; i < len; i++) {
formData.append("files", filesToUpload[i].file);
}
$.ajax({
data: formData,
processData: false,
contentType: false,
type: "POST",
success: function (data) {
},
error: function (data) {
alert("ERROR - " + data.responseText);
}
});
});
})()
PLIKI Z FORMULARZA IDĄ TUTAJ:
if(isset($_POST['submit'])) { $youremail = 'm.szkubiel@e-intermedia.pl';
$fromsubject = 'Temat wiadomości';
$name = $_POST['rodzaj_pojazdu'];
$mail = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['rok_produkcji'];
$poj_silnika = $_POST['poj_silnika'];
$moc_silnika = $_POST['moc_silnika'];
$przebieg = $_POST['przebieg'];
$lokalizacja = $_POST['lokalizacja'];
$przeglad = $_POST['przeglad'];
$liczba_wlascicieli = $_POST['liczba_wlascicieli'];
$message = $_POST['message'];
$tel = $_POST['tel'];
$adres_emai = $_POST['adres_emai'];
$message_uwagi = $_POST['message_uwagi'];
$skrzynia_biegow = $_POST['skrzynia_biegow'];
$naped = $_POST['naped'];
$drugi_komplet_kol = $_POST['drugi_komplet_kol'];
$wyposazenie = implode(', ', $_POST['wyposazenie']); $typ_silnika = $_POST['typ_silnika'];
if(count($_FILES['upload']['name']) > 0
){
mkdir('uploads/'.$createFolder);
for($i=0; $i<count($_FILES['upload']['name']); $i++) {
$tmpFilePath = $_FILES['upload']['tmp_name'][$i];
if($tmpFilePath != ""){
$shortname = $_FILES['upload']['name'][$i];
$explode = explode(".", $_FILES['upload']['name'][$i]); $filePath = "uploads/".$createFolder. '/' . rand().'.'.$explode[1
];
$files[] = $shortname;
}
}
}
}
$to = $youremail;
$headers .= "Reply-To: Some One <".$_POST['name'].">\r\n";
$headers .= "Return-Path: Some One <".$_POST['name'].">\r\n";
$headers .= "From: Some One <".$_POST['name'].">\r\n";
$headers .= "Organization: FCK AUTO\r\n";
$headers .= "Content-Type: text/html\r\n";
$mailsubject = $fromsubject;
$body .= $fromsubject.'
<table>
<tr> <td> Rodzaj pojazdu: </td> <td> '.$name.' </td> </tr>
<br>
<hr>
<tr> <td> Marka: </td> <td>'.$mail.'
<br>
<hr>
<tr> <td> Model: </td> <td>'.$subject.'
<br>
<hr>
<tr> <td> Rok produkcji: </td> <td>'.$message.'
<br>
<hr>
<tr> <td> Typ silnika: </td> <td>'.$typ_silnika.'
<br>
<hr>
<tr> <td> Pojemność silnika: </td> <td>'.$poj_silnika.'
<br>
<hr>
<tr> <td> Moc silnika:</td> <td> '.$moc_silnika.'
<br>
<hr>
<tr> <td> Przebieg:</td> <td> '.$przebieg.'
<br>
<hr>
<tr> <td> Skrzynia biegów: </td> <td>'.$skrzynia_biegow.'
<br>
<hr>
<tr> <td> Napęd: </td> <td>'.$naped.'
<br>
<hr>
<tr> <td> Drugi komplet kół:</td> <td> '.$drugi_komplet_kol.'
<br>
<hr>
<tr> <td> Lokalizacja: </td> <td>'.$lokalizacja.'
<br>
<hr>
<tr> <td> Przegląd: </td> <td>'.$przeglad.'
<br>
<hr>
<tr> <td> Łączna liczba właścicieli: </td> <td>'.$liczba_wlascicieli.'
<br>
<hr>
<tr> <td> Uwagi dotyczące stani technicznego: </td> <td>'.$message.'
<br>
<hr>
<tr> <td> Wyposażenie: </td> <td>'.$wyposazenie.'
<br>
<hr>
<tr> <td> Telefon:</td> <td> '.$tel.'
<br>
<hr>
<tr> <td> Adres e-mail:</td> <td> '.$adres_emai.'
<br>
<hr>
<tr> <td> UWAGI:</td> <td> '.$message_uwagi.'
<br>
<hr>
<a href="https://fck-auto.de/form/galeria.php?upload=/'.$createFolder.'">LINK DO GALERII</a>
<table>
';
echo "<div> Dziękujemy za przesłanie wiadomości, odezwiemy się w najbliższym czasie</div> <div>Za chwilę nastąpi powrót do strony...</div>
";
mail($to, $subject, $body,$headers); } else {
echo "You must write a message. </br> Please go to <a href='/index.html'>Home Page</a>"; }
?>
NA SAM KONIEC FORMULARZ ZOSTAJE WYSŁANY Z WSZYSTKIMI DANYMI Z INPUTÓW OPRÓCZ ZDJĘĆ.
Ten post edytował Cuncello 10.08.2020, 20:21:32