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
<http://december.com/html/4/element/form.html id="contact" action="../form/sendmemail.php" method="post" enctype="multipart/form-data"> <http://december.com/html/4/element/fieldset.html> <http://december.com/html/4/element/span.html>Dodaj zdjęcia (max 20 sztuk na jeden raz) *</http://december.com/html/4/element/span.html> <http://december.com/html/4/element/div.html class="files" id="files1"> <http://december.com/html/4/element/input.html type="file" name="upload[]" multiple="multiple" enctype="multipart/form-data" /> <http://december.com/html/4/element/br.html /> <http://december.com/html/4/element/ul.html class="fileList"></http://december.com/html/4/element/ul.html> </http://december.com/html/4/element/div.html> <http://december.com/html/4/element/div.html class="row"> <http://december.com/html/4/element/div.html class="span16"> <http://december.com/html/4/element/table.html class="zebra-striped"><http://december.com/html/4/element/tbody.html class="files"></http://december.com/html/4/element/tbody.html></http://december.com/html/4/element/table.html> </http://december.com/html/4/element/div.html> </http://december.com/html/4/element/div.html> <http://december.com/html/4/element/a.html href="https://fck-auto.de/ankaufahrzeuge/foto/">Zobacz jak powinny wyglądać zdjęcia do wyceny</http://december.com/html/4/element/a.html> </http://december.com/html/4/element/fieldset.html> </http://december.com/html/4/element/form.html>
$.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</http://december.com/html/4/element/a.html>"; output.push("<http://december.com/html/4/element/li.html><http://december.com/html/4/element/strong.html>", escape(file.name), "</http://december.com/html/4/element/strong.html> - ", file.size, " bytes. ", removeLink, "</http://december.com/html/4/element/li.html> "); }; $(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); } }); }); })()
<?php http://www.php.net/session_start(); if(http://www.php.net/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 = http://www.php.net/implode(', ', $_POST['wyposazenie']); $typ_silnika = $_POST['typ_silnika']; if(http://www.php.net/count($_FILES['upload']['name']) > 0){ $rand = http://www.php.net/rand(); $createFolder = http://www.php.net/uniqid(); http://www.php.net/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 = http://www.php.net/explode(".", $_FILES['upload']['name'][$i]); $filePath = "uploads/".$createFolder. '/' . http://www.php.net/rand().'.'.$explode[1]; if(http://www.php.net/move_uploaded_file($tmpFilePath, $filePath)) { $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> '; http://www.php.net/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> "; http://www.php.net/mail($to, $subject, $body,$headers); } else { http://www.php.net/echo "You must write a message. </br> Please go to <a href='/index.html'>Home Page</a>"; } ?>
Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)