Keywords for this topic
beschreibung, bild, name, type, div, files, error, mysql, bildname, image, return, width, align, echo, fail
by Thomas » Wed 12. Aug 2009, 21:19
- Code: Select all
<?php #--------------------------------------------------------------------------------# # \||/ # # | @___oo # # /\ /\ / (__,,,,| # # ) /^\) ^\/ _) # # ) /^\/ _) _/_/_/_/ _/_/_/_/ _/_/_/ _/_/ # # ) _ / / _) _/ _/ _/ _/ _/ # # /\ )/\/ || | )_) _/ _/_/_/ _/ _/_/ _/ _/ # # < > |(,,) )__) _/ _/ _/ _/ _/ _/ _/ # # || / \)___)\ _/_/ _/_/_/_/ _/_/_/ _/_/ # # | \____( )___) )___ # # \______(_______;;; __;;; # # # #----------------------------------------------------------------by Thomas---------# error_reporting(E_ALL);
////////////////////////////////////////////////////////////////////////////////// // // // Datenbank verbindung // // // ////////////////////////////////////////////////////////////////////////////////// function db_connect() { $hostname = "localhost"; $database = "datenbank"; // deine Datenbank $username = "benutzername"; // dein Benutzername $password = "passwort"; // dein Passwort $result = mysql_pconnect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR); mysql_select_db($database, $result); return $result; } ////////////////////////////////////////////////////////////////////////////////// // // // Fehler Ausgabe // // // //////////////////////////////////////////////////////////////////////////////////
function fail($string) { echo "<div align=\"center\">".$string."<p> </p><a href=\"javascript:history.back()\">Zurück</a></div>"; return; } ////////////////////////////////////////////////////////////////////////////////// // // // Der Bilderupload // // // //////////////////////////////////////////////////////////////////////////////////
$con = db_connect();
if (isset($_POST['send'])) { $beschreibung = $_POST['beschreibung']; $beschreibung = trim($beschreibung); // Hier kannst du bestimmen was alles gespeichert wird. $beschreibung = strip_tags($beschreibung); // ob html gespeichert werden darf oder nicht etc. $beschreibung = htmlentities($beschreibung); $beschreibung = stripslashes($beschreibung); $beschreibung = nl2br($beschreibung); $endung =substr(strrchr($_FILES['bild']['name'], '.'), 1); $type = $_FILES['bild']['type']; $uploadpfad = $_SERVER['DOCUMENT_ROOT']."/benutzerbilder/";
if($_FILES['bild']['size'] > 102400) { fail("Ihr Bild ist zu groß. Es sind max. 100kb erlaubt."); return; } if ($type != 'image/jpeg' AND $type != 'image/jpg' AND $type != 'image/pjpeg' AND $type != 'image/png') { fail("Ihr Bild darf nur im Format .png oder .jpg sein!"); return; } if($_FILES['bild']['name']!="") { $bildname = $_FILES['bild']['name'] = time().".".$endung; // Hier bekommt dein Bild einen neuen Namen, damit keine Doppelnamen vorhanden sind. } if (move_uploaded_file($_FILES['bild']['tmp_name'], $uploadpfad.$bildname)) { chmod ($uploadpfad.$bildname, 0644); // Hier kannst du die Bildrechte ändern. $insert = "INSERT INTO bilder (bild, beschreibung) VALUES ('".$bildname."', '".$beschreibung."')"; $query = mysql_query($insert, $con) or die(mysql_error()); echo "Ihre Daten wurden gespeichert!"; } } else { echo '<form action="upload.php" method="post" enctype="multipart/form-data" name="upload" id="upload"> <table width="100%" border="0" bgcolor="#EEEEEE"> <tr> <td width="30%">Bild:</td> <td width="70%"><div align="left"> <input name="bild" type="file" size="30" /> Bildtypen: .jpg, .png <br /> <br /> <strong>! ! ! ACHTUNG ! ! !</strong><br /> Max. Bildgröße ist 100 kb.</div></td> </tr> <tr> <td>Beschreibung:</td> <td><div align="left"> <textarea name="beschreibung" cols="50" rows="6"></textarea> </div></td> </tr> <tr> <td> </td> <td><input type="submit" name="Submit" value="Bild Speichern" /> <input name="send" type="hidden" id="send" value="1" /></td> </tr> </table> </form>'; } ?>
-

Thomas
- Administrator

-
Users Information
- Posts: 6957
- Articles: 3
- Joined: Sat 6. Dec 2008, 17:54
- Location: Ismaning
- Group: Administrators
- Gender:
- Country:
 - Images: 1574
- First Name: Thomas
- PLZ: 85737
- Wohnort: Ismaning
- Bundesland: Bayern
-
-
Who is online
Users browsing this forum: No registered users and 1 guest
Return to Scriptbörse: Angebote
|
 |
|