PSD-Tutorials.de
Forum für Design, Fotografie & Bildbearbeitung
Tutkit
Agentur
Hilfe
Kontakt
Start
Forum
Aktuelles
Besonderer Inhalt
Foren durchsuchen
Tutorials
News
Anmelden
Kostenlos registrieren
Aktuelles
Suche
Suche
Nur Titel durchsuchen
Von:
Menü
Anmelden
Kostenlos registrieren
App installieren
Installieren
JavaScript ist deaktiviert. Für eine bessere Darstellung aktiviere bitte JavaScript in deinem Browser, bevor du fortfährst.
Du verwendest einen veralteten Browser. Es ist möglich, dass diese oder andere Websites nicht korrekt angezeigt werden.
Du solltest ein Upgrade durchführen oder einen
alternativen Browser
verwenden.
Antworten auf deine Fragen:
Neues Thema erstellen
Start
Forum
Sonstiges
Webdesign, Webentwicklung & Programmierung
PHP, Javascript, jQuery, Ajax, nodeJS, MySQL...
php + mysql: bildupload in ext. verzeichnis + bildnamen in datenbank speichern, wie?
Beitrag
<blockquote data-quote="richy149" data-source="post: 2230793"><p><strong>AW: php + mysql: bildupload in ext. verzeichnis + bildnamen in datenbank speichern, w</strong></p><p></p><p>Hi,</p><p>ich habe eine ähnliches Script Problem.</p><p>Ich habe ein Upload-Formuluar gestaltet, wo User Ihren Namen, Ihre Mail und eben eine Foto uploaden können.</p><p>Diese Daten werden in einen SQL DB gespeichert. Das funktioniert auch alles - bis eben auf den Dateinamen der hochgeladenen Datei, dieses Feld in der SQL-DB bleibt leer.</p><p>Ich hab das ganze mit dem phpFormGenerator erstellt. Vielleicht kann mir hier jemand helfen. Ich bin was PHP & SQL angeht nicht sehr bewandert <img src="/styles/default/xenforo/smilies/zwinker.gif" class="smilie" loading="lazy" alt=";)" title="Wink ;)" data-shortname=";)" /></p><p></p><p>Das hochladen der Datei selbst klappt. Aber der Dateiname wird nicht gespeichert.</p><p></p><p>Meine form.html</p><p>[HTML]</p><p></p><p> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"></p><p> <html></p><p> <head></p><p> <title>Upload - created by phpFormGenerator</title></p><p> <meta http-equiv="content-type" content="text/html; charset=UTF-8"><link href="style.css" rel="stylesheet" type="text/css"></p><p> <!-- calendar stuff --></p><p> <link rel="stylesheet" type="text/css" href="calendar/calendar-blue2.css" /></p><p> <script type="text/javascript" src="calendar/calendar.js"></script></p><p> <script type="text/javascript" src="calendar/calendar-en.js"></script></p><p> <script type="text/javascript" src="calendar/calendar-setup.js"></script></p><p> <!-- END calendar stuff --></p><p></p><p> <!-- expand/collapse function --></p><p> <SCRIPT type=text/javascript></p><p> <!--</p><p> function collapseElem(obj)</p><p> {</p><p> var el = document.getElementById(obj);</p><p> el.style.display = 'none';</p><p> }</p><p></p><p></p><p> function expandElem(obj)</p><p> {</p><p> var el = document.getElementById(obj);</p><p> el.style.display = '';</p><p> }</p><p></p><p></p><p> //--></p><p> </SCRIPT></p><p> <!-- expand/collapse function --></p><p></p><p></p><p> <!-- expand/collapse function --></p><p> <SCRIPT type=text/javascript></p><p> <!--</p><p></p><p> // collapse all elements, except the first one</p><p> function collapseAll()</p><p> {</p><p> var numFormPages = 1;</p><p></p><p> for(i=2; i <= numFormPages; i++)</p><p> {</p><p> currPageId = ('mainForm_' + i);</p><p> collapseElem(currPageId);</p><p> }</p><p> }</p><p></p><p></p><p> //--></p><p> </SCRIPT></p><p> <!-- expand/collapse function --></p><p></p><p></p><p> <!-- validate --></p><p> <SCRIPT type=text/javascript></p><p> <!--</p><p> function validateField(fieldId, fieldBoxId, fieldType, required)</p><p> {</p><p> fieldBox = document.getElementById(fieldBoxId);</p><p> fieldObj = document.getElementById(fieldId);</p><p></p><p> if(fieldType == 'text' || fieldType == 'textarea' || fieldType == 'password' || fieldType == 'file' || fieldType == 'phone' || fieldType == 'website')</p><p> { </p><p> if(required == 1 && fieldObj.value == '')</p><p> {</p><p> fieldObj.setAttribute("class","mainFormError");</p><p> fieldObj.setAttribute("className","mainFormError");</p><p> fieldObj.focus();</p><p> return false; </p><p> }</p><p></p><p> }</p><p></p><p></p><p> else if(fieldType == 'menu' || fieldType == 'country' || fieldType == 'state')</p><p> { </p><p> if(required == 1 && fieldObj.selectedIndex == 0)</p><p> { </p><p> fieldObj.setAttribute("class","mainFormError");</p><p> fieldObj.setAttribute("className","mainFormError");</p><p> fieldObj.focus();</p><p> return false; </p><p> }</p><p></p><p> }</p><p></p><p></p><p> else if(fieldType == 'email')</p><p> { </p><p> if((required == 1 && fieldObj.value=='') || (fieldObj.value!='' && !validate_email(fieldObj.value)))</p><p> { </p><p> fieldObj.setAttribute("class","mainFormError");</p><p> fieldObj.setAttribute("className","mainFormError");</p><p> fieldObj.focus();</p><p> return false; </p><p> }</p><p></p><p> }</p><p></p><p></p><p></p><p> }</p><p></p><p> function validate_email(emailStr)</p><p> { </p><p> apos=emailStr.indexOf("@");</p><p> dotpos=emailStr.lastIndexOf(".");</p><p></p><p> if (apos<1||dotpos-apos<2) </p><p> {</p><p> return false;</p><p> }</p><p> else</p><p> {</p><p> return true;</p><p> }</p><p> }</p><p></p><p></p><p> function validateDate(fieldId, fieldBoxId, fieldType, required, minDateStr, maxDateStr)</p><p> {</p><p> retValue = true;</p><p></p><p> fieldBox = document.getElementById(fieldBoxId);</p><p> fieldObj = document.getElementById(fieldId); </p><p> dateStr = fieldObj.value;</p><p></p><p></p><p> if(required == 0 && dateStr == '')</p><p> {</p><p> return true;</p><p> }</p><p></p><p></p><p> if(dateStr.charAt(2) != '/' || dateStr.charAt(5) != '/' || dateStr.length != 10)</p><p> {</p><p> retValue = false;</p><p> } </p><p></p><p> else // format's okay; check max, min</p><p> {</p><p> currDays = parseInt(dateStr.substr(0,2),10) + parseInt(dateStr.substr(3,2),10)*30 + parseInt(dateStr.substr(6,4),10)*365;</p><p> //alert(currDays);</p><p></p><p> if(maxDateStr != '')</p><p> {</p><p> maxDays = parseInt(maxDateStr.substr(0,2),10) + parseInt(maxDateStr.substr(3,2),10)*30 + parseInt(maxDateStr.substr(6,4),10)*365;</p><p> //alert(maxDays);</p><p> if(currDays > maxDays)</p><p> retValue = false;</p><p> }</p><p></p><p> if(minDateStr != '')</p><p> {</p><p> minDays = parseInt(minDateStr.substr(0,2),10) + parseInt(minDateStr.substr(3,2),10)*30 + parseInt(minDateStr.substr(6,4),10)*365;</p><p> //alert(minDays);</p><p> if(currDays < minDays)</p><p> retValue = false;</p><p> }</p><p> }</p><p></p><p> if(retValue == false)</p><p> {</p><p> fieldObj.setAttribute("class","mainFormError");</p><p> fieldObj.setAttribute("className","mainFormError");</p><p> fieldObj.focus();</p><p> return false;</p><p> }</p><p> }</p><p> //--></p><p> </SCRIPT></p><p> <!-- end validate --></p><p></p><p></p><p></p><p></p><p> </head></p><p></p><p> <body onLoad="collapseAll()"></p><p></p><p> <div id="mainForm"></p><p></p><p></p><p></p><p></p><p> <div id="formHeader"></p><p> <h2 class="formInfo">Upload</h2></p><p> <p class="formInfo">1...2...3... mein Genussklick:</p><p>So einfach kann gewinnen sein! </p></p><p> </div></p><p></p><p></p><p> <BR/><!-- begin form --></p><p> <form method=post enctype=multipart/form-data action=processor.php onSubmit="return validatePage1();"><ul class=mainForm id="mainForm_1"></p><p></p><p> <li class="mainForm" id="fieldBox_1"></p><p> <label class="formFieldQuestion">Name&nbsp;*</label><input class=mainForm type=text name=field_1 id=field_1 size='20' value=''></li></p><p></p><p> <li class="mainForm" id="fieldBox_2"></p><p> <label class="formFieldQuestion">E-Mail&nbsp;*</label><input class=mainForm type=email name=field_2 id=field_2 size=20 value="" style="background-image:url(imgs/email.png); background-repeat: no-repeat; padding: 2px 2px 2px 25px;"></li></p><p></p><p> <li class="mainForm" id="fieldBox_3"></p><p> <label class="formFieldQuestion">Bild-Upload&nbsp;*</label><input class=mainForm type=file name=field_3 id=field_3 value=""></li></p><p></p><p> <li class="mainForm" id="fieldBox_4"></p><p> <label class="formFieldQuestion">Ich bin der Urheber des Bildes und erteile dem Sigibaldus e.V. die Nutzungsrechte&nbsp;*</label><span><input class=mainForm type=checkbox name=field_4[] id=field_4_option_1 value="Ja" /><label class=formFieldOption for="field_4_option_1">Ja</label></span></li></p><p> </p><p> </p><p> <!-- end of this page --></p><p></p><p> <!-- page validation --></p><p> <SCRIPT type=text/javascript></p><p> <!--</p><p> function validatePage1()</p><p> {</p><p> retVal = true;</p><p> if (validateField('field_1','fieldBox_1','text',1) == false)</p><p> retVal=false;</p><p>if (validateField('field_2','fieldBox_2','email',1) == false)</p><p> retVal=false;</p><p>if (validateField('field_3','fieldBox_3','file',1) == false)</p><p> retVal=false;</p><p>if (validateField('field_4','fieldBox_4','checkbox',1) == false)</p><p> retVal=false;</p><p></p><p> if(retVal == false)</p><p> {</p><p> alert('Please correct the errors. Fields marked with an asterisk (*) are required');</p><p> return false;</p><p> }</p><p> return retVal;</p><p> }</p><p> //--></p><p> </SCRIPT></p><p></p><p> <!-- end page validaton --></p><p></p><p></p><p></p><p> <!-- next page buttons --><li class="mainForm"></p><p> <input id="saveForm" class="mainForm" type="submit" value="Submit" /></p><p> </li></p><p></p><p> </form></p><p> <!-- end of form --></p><p> <!-- close the display stuff for this page --></p><p> </ul></div><div id="footer"><p class="footer"><a class=footer href=http://phpformgen.sourceforge.net>Generated by phpFormGenerator</a></p></div></p><p></p><p> </body></p><p> </html>[/HTML]Meine processer.php</p><p>[PHP]<?php</p><p></p><p>$where_form_is="http://".$_SERVER['SERVER_NAME'].strrev(strstr(strrev($_SERVER['PHP_SELF']),"/"));</p><p></p><p>// File upload handling</p><p>if($_FILES['field_3']['name']!=''){</p><p>$field_3_filename = "file_3_".date("sihdmY").substr($_FILES['field_3']['name'],strlen($_FILES['field_3']['name'])-4);</p><p>if(!move_uploaded_file($_FILES['field_3']['tmp_name'], "./files/".$field_3_filename)){</p><p>die("File " . $_FILES['field_3']['name'] . " was not uploaded.");</p><p>}</p><p>}</p><p></p><p>// Checkbox handling</p><p>$field_4_opts = $_POST['field_4'][0];</p><p></p><p>include("config.inc.php");</p><p>$link = mysql_connect($db_host,$db_user,$db_pass);</p><p>if(!$link) die ('Could not connect to database: '.mysql_error());</p><p>mysql_select_db($db_name,$link);</p><p>$query = "INSERT into `".$db_table."` (field_1,field_2,field_3,field_4) VALUES ('" . $_POST['field_1'] . "','" . $_POST['field_2'] . "','" . $_POST['field_3'] . "','" . $_POST['field_4'] . "')";</p><p>mysql_query($query);</p><p>mysql_close($link);</p><p></p><p>include("confirm.html");</p><p></p><p>?>[/PHP]SQL-Struktur:</p></blockquote><p></p>
[QUOTE="richy149, post: 2230793"] [b]AW: php + mysql: bildupload in ext. verzeichnis + bildnamen in datenbank speichern, w[/b] Hi, ich habe eine ähnliches Script Problem. Ich habe ein Upload-Formuluar gestaltet, wo User Ihren Namen, Ihre Mail und eben eine Foto uploaden können. Diese Daten werden in einen SQL DB gespeichert. Das funktioniert auch alles - bis eben auf den Dateinamen der hochgeladenen Datei, dieses Feld in der SQL-DB bleibt leer. Ich hab das ganze mit dem phpFormGenerator erstellt. Vielleicht kann mir hier jemand helfen. Ich bin was PHP & SQL angeht nicht sehr bewandert ;) Das hochladen der Datei selbst klappt. Aber der Dateiname wird nicht gespeichert. Meine form.html [HTML] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Upload - created by phpFormGenerator</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"><link href="style.css" rel="stylesheet" type="text/css"> <!-- calendar stuff --> <link rel="stylesheet" type="text/css" href="calendar/calendar-blue2.css" /> <script type="text/javascript" src="calendar/calendar.js"></script> <script type="text/javascript" src="calendar/calendar-en.js"></script> <script type="text/javascript" src="calendar/calendar-setup.js"></script> <!-- END calendar stuff --> <!-- expand/collapse function --> <SCRIPT type=text/javascript> <!-- function collapseElem(obj) { var el = document.getElementById(obj); el.style.display = 'none'; } function expandElem(obj) { var el = document.getElementById(obj); el.style.display = ''; } //--> </SCRIPT> <!-- expand/collapse function --> <!-- expand/collapse function --> <SCRIPT type=text/javascript> <!-- // collapse all elements, except the first one function collapseAll() { var numFormPages = 1; for(i=2; i <= numFormPages; i++) { currPageId = ('mainForm_' + i); collapseElem(currPageId); } } //--> </SCRIPT> <!-- expand/collapse function --> <!-- validate --> <SCRIPT type=text/javascript> <!-- function validateField(fieldId, fieldBoxId, fieldType, required) { fieldBox = document.getElementById(fieldBoxId); fieldObj = document.getElementById(fieldId); if(fieldType == 'text' || fieldType == 'textarea' || fieldType == 'password' || fieldType == 'file' || fieldType == 'phone' || fieldType == 'website') { if(required == 1 && fieldObj.value == '') { fieldObj.setAttribute("class","mainFormError"); fieldObj.setAttribute("className","mainFormError"); fieldObj.focus(); return false; } } else if(fieldType == 'menu' || fieldType == 'country' || fieldType == 'state') { if(required == 1 && fieldObj.selectedIndex == 0) { fieldObj.setAttribute("class","mainFormError"); fieldObj.setAttribute("className","mainFormError"); fieldObj.focus(); return false; } } else if(fieldType == 'email') { if((required == 1 && fieldObj.value=='') || (fieldObj.value!='' && !validate_email(fieldObj.value))) { fieldObj.setAttribute("class","mainFormError"); fieldObj.setAttribute("className","mainFormError"); fieldObj.focus(); return false; } } } function validate_email(emailStr) { apos=emailStr.indexOf("@"); dotpos=emailStr.lastIndexOf("."); if (apos<1||dotpos-apos<2) { return false; } else { return true; } } function validateDate(fieldId, fieldBoxId, fieldType, required, minDateStr, maxDateStr) { retValue = true; fieldBox = document.getElementById(fieldBoxId); fieldObj = document.getElementById(fieldId); dateStr = fieldObj.value; if(required == 0 && dateStr == '') { return true; } if(dateStr.charAt(2) != '/' || dateStr.charAt(5) != '/' || dateStr.length != 10) { retValue = false; } else // format's okay; check max, min { currDays = parseInt(dateStr.substr(0,2),10) + parseInt(dateStr.substr(3,2),10)*30 + parseInt(dateStr.substr(6,4),10)*365; //alert(currDays); if(maxDateStr != '') { maxDays = parseInt(maxDateStr.substr(0,2),10) + parseInt(maxDateStr.substr(3,2),10)*30 + parseInt(maxDateStr.substr(6,4),10)*365; //alert(maxDays); if(currDays > maxDays) retValue = false; } if(minDateStr != '') { minDays = parseInt(minDateStr.substr(0,2),10) + parseInt(minDateStr.substr(3,2),10)*30 + parseInt(minDateStr.substr(6,4),10)*365; //alert(minDays); if(currDays < minDays) retValue = false; } } if(retValue == false) { fieldObj.setAttribute("class","mainFormError"); fieldObj.setAttribute("className","mainFormError"); fieldObj.focus(); return false; } } //--> </SCRIPT> <!-- end validate --> </head> <body onLoad="collapseAll()"> <div id="mainForm"> <div id="formHeader"> <h2 class="formInfo">Upload</h2> <p class="formInfo">1...2...3... mein Genussklick: So einfach kann gewinnen sein! </p> </div> <BR/><!-- begin form --> <form method=post enctype=multipart/form-data action=processor.php onSubmit="return validatePage1();"><ul class=mainForm id="mainForm_1"> <li class="mainForm" id="fieldBox_1"> <label class="formFieldQuestion">Name *</label><input class=mainForm type=text name=field_1 id=field_1 size='20' value=''></li> <li class="mainForm" id="fieldBox_2"> <label class="formFieldQuestion">E-Mail *</label><input class=mainForm type=email name=field_2 id=field_2 size=20 value="" style="background-image:url(imgs/email.png); background-repeat: no-repeat; padding: 2px 2px 2px 25px;"></li> <li class="mainForm" id="fieldBox_3"> <label class="formFieldQuestion">Bild-Upload *</label><input class=mainForm type=file name=field_3 id=field_3 value=""></li> <li class="mainForm" id="fieldBox_4"> <label class="formFieldQuestion">Ich bin der Urheber des Bildes und erteile dem Sigibaldus e.V. die Nutzungsrechte *</label><span><input class=mainForm type=checkbox name=field_4[] id=field_4_option_1 value="Ja" /><label class=formFieldOption for="field_4_option_1">Ja</label></span></li> <!-- end of this page --> <!-- page validation --> <SCRIPT type=text/javascript> <!-- function validatePage1() { retVal = true; if (validateField('field_1','fieldBox_1','text',1) == false) retVal=false; if (validateField('field_2','fieldBox_2','email',1) == false) retVal=false; if (validateField('field_3','fieldBox_3','file',1) == false) retVal=false; if (validateField('field_4','fieldBox_4','checkbox',1) == false) retVal=false; if(retVal == false) { alert('Please correct the errors. Fields marked with an asterisk (*) are required'); return false; } return retVal; } //--> </SCRIPT> <!-- end page validaton --> <!-- next page buttons --><li class="mainForm"> <input id="saveForm" class="mainForm" type="submit" value="Submit" /> </li> </form> <!-- end of form --> <!-- close the display stuff for this page --> </ul></div><div id="footer"><p class="footer"><a class=footer href=http://phpformgen.sourceforge.net>Generated by phpFormGenerator</a></p></div> </body> </html>[/HTML]Meine processer.php [PHP]<?php $where_form_is="http://".$_SERVER['SERVER_NAME'].strrev(strstr(strrev($_SERVER['PHP_SELF']),"/")); // File upload handling if($_FILES['field_3']['name']!=''){ $field_3_filename = "file_3_".date("sihdmY").substr($_FILES['field_3']['name'],strlen($_FILES['field_3']['name'])-4); if(!move_uploaded_file($_FILES['field_3']['tmp_name'], "./files/".$field_3_filename)){ die("File " . $_FILES['field_3']['name'] . " was not uploaded."); } } // Checkbox handling $field_4_opts = $_POST['field_4'][0]; include("config.inc.php"); $link = mysql_connect($db_host,$db_user,$db_pass); if(!$link) die ('Could not connect to database: '.mysql_error()); mysql_select_db($db_name,$link); $query = "INSERT into `".$db_table."` (field_1,field_2,field_3,field_4) VALUES ('" . $_POST['field_1'] . "','" . $_POST['field_2'] . "','" . $_POST['field_3'] . "','" . $_POST['field_4'] . "')"; mysql_query($query); mysql_close($link); include("confirm.html"); ?>[/PHP]SQL-Struktur: [/QUOTE]
Bilder bitte
hier hochladen
und danach über das Bild-Icon (Direktlink vorher kopieren) platzieren.
Zitate einfügen…
Authentifizierung
Wenn ▲ = 5, ▼ = 2 und ■ = 7, was ist ▲ × ▼ + ■?
Antworten
Start
Forum
Sonstiges
Webdesign, Webentwicklung & Programmierung
PHP, Javascript, jQuery, Ajax, nodeJS, MySQL...
php + mysql: bildupload in ext. verzeichnis + bildnamen in datenbank speichern, wie?
Oben