Erstellung des CapchtaCodes und Vorschaubilder

This commit is contained in:
2026-05-24 11:18:35 +00:00
parent 4fac3121f3
commit 810ac71e29
13 changed files with 567 additions and 4 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
# SGD Projekt
### Version 1
### Version 2
hier wird das SGD Projekt hochgeladen und verwaltet
+85
View File
@@ -0,0 +1,85 @@
<?php
/**
* Start der Session
*/
session_start();
?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<title>Bild speichern </title>
<meta name="viewport" content=
"width=device-width, initial-scale=1.0">
</head>
<body>
<?php
class Bildspeichern {
public function datup() {
if (isset($_FILES['datei'])) {
if (($_FILES['datei']['size'] > 100000) ||
(filesize($_FILES['datei']['tmp_name'])
> 100000)) {
echo "Die Dateigr&ouml;&#946;e ist auf " .
"100.000 Byte beschr&auml;nkt.<br>" .
"Verkleinern Sie das Bild bitte mit " .
"einem geeigneten Grafikprogramm.<br>";
}
else if (($_FILES['datei']['type'] != "image/png")
&& ($_FILES['datei']['type'] != "image/pjpeg")
&& ($_FILES['datei']['type'] != "image/jpeg")) {
echo "Es d&uuml;rfen nur Bilddateien vom Typ" .
" PNG oder JPEG hochgeladen werden.<br>";
} else if (!empty($_FILES['datei']['name'])) {
$dateiname = $_SESSION["name"] . time();
if ($_FILES['datei']['type'] != "image/png") {
$dateiname .= ".jpg";
} else {
$dateiname .= ".png";
}
$_SESSION["dateiname"] = $dateiname;
if (move_uploaded_file(
$_FILES['datei']['tmp_name'],
'images/' . $dateiname)) {
@include ("db.inc.php");
if ($stmt = $pdo -> prepare(
"SELECT userid, id_mitglied FROM mitglieder")) {
$stmt -> execute();
while ($row = $stmt -> fetch()) {
if ($_SESSION["name"] == $row["userid"]) {
$_SESSION["id_mitglied"] = $row["id_mitglied"];
break;
}
}
}
if ($stmt = $pdo -> prepare(
"INSERT INTO fragen" .
" (bild, zusatzinfos, id_mitglied) " .
" VALUES (:bild, :zusatzinfos, :userid)")) {
if ($stmt -> execute(
array(
':bild' => $_SESSION["dateiname"],
':zusatzinfos' => $_POST["zusatzinfos"],
':userid' => $_SESSION["id_mitglied"]
)
)) {
$dat = "upload_ok.php";
} else {
$dat = "upload_fehler.php";
}
header("Location: $dat");
}
}
}
echo "<hr><a href='index.php'>Zur Homepage</a>";
}
}
}
$obj = new Bildspeichern();
$obj -> datup();
?>
</body>
</html>
+44
View File
@@ -0,0 +1,44 @@
<?php
/**
* Start der Session
*/
session_start();
unset($_SESSION['captchacode']);
// Zeichen, die der Captchacode enthalten darf
$moeglicheZeichen = "abcdefghiklmnpqrstuvwxy123456789" .
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// Anzahl der Zeichen, die das Captcha enthalten soll
$anzahlZeichen = 4;
// Captcha-Variable
$captchacode = "";
// Füllen der Captcha-Variable mit der festgelegten
// Anzahl zufälliger Zeichen
for ($i = 0; $i < $anzahlZeichen; $i++) {
$captchacode .= substr($moeglicheZeichen,
(rand() % (strlen($moeglicheZeichen))), 1);
}
// Schreiben des Captchacodes in die Session
$_SESSION['captchacode'] = $captchacode;
header('Content-type: image/jpg');
$image = imagecreate(350, 130);
$farben = array();
for ($i = 0; $i < $anzahlZeichen; $i++) {
$farben[$i] = imagecolorallocate($image,
rand(0, 255), rand(0, 255), rand(0, 255));
}
$bgc = imagecolorallocate($image, 230, 230, 230);
imagefill($image, 0, 0, $bgc);
for ($i = 0; $i < $anzahlZeichen; $i++) {
ImageTTFText($image, rand(20, 80), rand(-20, 60),
50 + ($i * 50), rand(80, 120),
$farben[rand(0, $anzahlZeichen - 1)],
"fonts/Anorexia.ttf", $captchacode[$i]);
}
for ($i = 0; $i < $anzahlZeichen; $i++) {
imageline($image, rand(0, 10), rand(0, 150),
rand(330, 340), rand(0, 150), $farben[$i]);
}
imagejpeg($image);
imagedestroy($image);
?>
Binary file not shown.
Binary file not shown.
Binary file not shown.
+5 -3
View File
@@ -29,12 +29,12 @@ class MeineAusnahme extends Exception{};
try {
if (isset($_SESSION["login"]) && ($_SESSION["login"] == "true")) {
if (@include("navmitglieder.php"));{
if (!@include("navmitglieder.php")){
throw new MeineAusnahme();
}
}
else {
if (@include("nav.php"));{
if (!@include("nav.php")){
throw new MeineAusnahme();
}
}
@@ -43,7 +43,7 @@ class MeineAusnahme extends Exception{};
die("<h1>Image2Food - Sag mir was ich daraus kochen kann</h1>
<h2>Das soziale, multimediale Netzwerk für Kochideen</h2>
<p> Leider gibt es ein Problem mit der Webseite.
Wir arbeiten daran mit Hochdruck. Besuchen Sie uns in kürze wieder enu</p>");
Wir arbeiten daran mit Hochdruck. Besuchen Sie uns in kürze wieder erneut</p>");
}
?>
</div>
@@ -59,6 +59,8 @@ class MeineAusnahme extends Exception{};
function besucher() {
if (isset($_SESSION["login"]) && ($_SESSION["login"] == "true")){
echo "<div id='indextext'><h3>Mitgliederbereich</h3><br>Sie sind Angemeldet</div>";
@include("uploadformular.inc.php");
echo "<a href='vorschaubilder.php'" ." target='vorschau'>Vorschau</a>";
} elseif (isset($_SESSION["login"]) && ($_SESSION["login"] == "false")){
echo "<div id='indextext'> Sie können sich jetzt zum Mitgliederbereich anmelden. </div>";
} elseif (isset($_COOKIE['Image2Food'])){
+337
View File
@@ -0,0 +1,337 @@
// Elemente und Universalselektor
* {
margin: 0;
padding: 0;
border: 0;
outline: 0;
vertical-align: baseline;
background: transparent;
}
body {
background: #145D05;
color: white;
}
h1, h2, h3, h4, h5 {
display: block;
text-align: center;
margin: 15px;
padding: 5px;
border-style: groove;
border-width: 1pt;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
}
a {
color: white;
background: #6C0610;
text-decoration: none;
display: inline-block;
min-width: 85px;
height: 20px;
text-align: center;
margin: 5px;
padding: 5px;
border-style: groove;
border-width: 1pt;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 5px 2px 3px #888;
-webkit-box-shadow: 5px 2px 3px #888;
box-shadow: 5px 2px 3px #888;
}
form {
background: white;
color: #145D05;
margin: 5px;
padding: 10px;
border-style: inset;
border-width: 3pt;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 5px 5px 5px #888;
-webkit-box-shadow: 5px 5px 5px #888;
-moz-box-shadow: 5px 2px 3px #888;
-webkit-box-shadow: 5px 2px 3px #888;
box-shadow: 5px 2px 3px #888;
}
textarea {
margin: 10px;
padding: 10px;
border-style: solid;
border-width: 1pt;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 5px 5px 5px #888;
-webkit-box-shadow: 5px 5px 5px #888;
-moz-box-shadow: 5px 2px 3px #888;
-webkit-box-shadow: 5px 2px 3px #888;
box-shadow: 5px 2px 3px #888;
}
input {
margin: 5px;
padding: 2px;
border-style: solid;
border-width: 1pt;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 5px 5px 5px #888;
-webkit-box-shadow: 5px 5px 5px #888;
-moz-box-shadow: 5px 2px 3px #888;
-webkit-box-shadow: 5px 2px 3px #888;
box-shadow: 5px 2px 3px #888;
}
// Klassen
.hlink {
text-decoration: none;
display: inline-block;
height: 35px;
text-align: center;
margin: 5px;
padding: 5px;
border-style: groove;
border-width: 1pt;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 5px 2px 3px #888;
-webkit-box-shadow: 5px 2px 3px #888;
box-shadow: 5px 2px 3px #888;
}
.spezielleUeber {
background: white;
color: #145D05;
font-size: 110%;
}
.reg_label {
display: inline-block;
width: 200px;
}
a:hover {
color: #145D05;
background: white;
}
.hlink:hover {
color: white;
background: #6C0610;
}
.thumb {
width: 120px;
height: 160px;
display: inline-block;
margin: 10px;
padding: 10px;
overflow: hidden;
border-style: groove;
border-width: 1pt;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 5px 2px 3px #888;
-webkit-box-shadow: 5px 2px 3px #888;
box-shadow: 5px 2px 3px #888;
}
.fehlermeldung {
color: #6C0610;
}
.captcha {
width: 200px;
margin: 10px;
border-style: groove;
border-width: 1pt;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 5px 2px 3px #888;
-webkit-box-shadow: 5px 2px 3px #888;
box-shadow: 5px 2px 3px #888;
}
.detailbildcontainer {
height: 250px;
width: 250px;
margin: 3px;
}
.detailbild {
max-height: 320px;
max-width: 320px;
padding: 3px;
}
.vorschauinfos {
color: #145D05;
background: white;
margin: 5px;
padding: 15px;
width: 650px;
max-height: 150px;
overflow: scroll;
border-style: inline;
border-width: 1pt;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
}
.hlink_klein {
text-decoration: none;
height: 18px;
width: 110px;
text-align: center;
margin: 2px;
padding: 2px;
font-size: 12px;
border-style: groove;
border-width: 1pt;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 5px 2px 3px #888;
-webkit-box-shadow: 5px 2px 3px #888;
box-shadow: 5px 2px 3px #888;
}
.hlink_nix {
color: white;
background: #145D05;
text-decoration: none;
display: inline-block;
min-width: 85px;
height: auto;
text-align: center;
margin: 5px;
padding: 5px;
text-decoration: none;
text-align: left;
margin: 2px;
padding: 2px;
font-size: 0px;
border-style: none;
border-width: 0pt;
-moz-border-radius: 0px;
-webkit-border-radius: 0px;
border-radius: 0px;
-moz-box-shadow: 0px 0px 0px #888;
-webkit-box-shadow: 0px 0px 0px #888;
box-shadow: 0px 0px 0px #888;
}
.thumb_bild {
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
border-radius: 3px;
border-style: dotted;
border-width: 1pt;
opacity: 0.9;
color: #888;
}
.thumb_bild:hover {
border-style: groove;
color: white;
opacity: 1;
-moz-box-shadow: 2px 2px 3px #888;
-webkit-box-shadow: 2px 2px 3px #888;
box-shadow: 2px 2px 3px #888;
}
.rezepttab {
width: 950px;
margin: 5px;
}
// IDs
#detailbereich {
height: 550px;
width: 98%;
margin: auto;
border-style: groove;
border-width: 1pt;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 5px 2px 3px #888;
-webkit-box-shadow: 5px 2px 3px #888;
box-shadow: 5px 2px 3px #888;
overflow-x: scroll;
}
#vorschauber {
height: 300px;
width: 98%;
margin: auto;
border-style: groove;
border-width: 1pt;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 5px 2px 3px #888;
-webkit-box-shadow: 5px 2px 3px #888;
box-shadow: 5px 2px 3px #888;
overflow-x: scroll;
}
#nav {
width: 1000px;
height: 40px;
margin: auto;
padding: 10px;
}
#content {
width: 1000px;
margin: auto;
padding: 20px;
border-style: groove;
border-width: 1pt;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
}
#indextext {
text-align: justify;
background: white;
color: #145D05;
margin: 5px;
padding: 10px;
border-style: inset;
border-width: 3pt;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 5px 5px 5px #888;
-webkit-box-shadow: 5px 5px 5px #888;
box-shadow: 5px 5px 5px #888;
}
#meldung {
position: relative;
top: -200px;
margin: 0 auto;
opacity: 0.7;
visibility: hidden;
background: white;
color: #6C0610;
width: 450px;
min-height: 40px;
padding: 20px;
border-style: inset;
border-width: 3pt;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 5px 5px 5px #888;
-webkit-box-shadow: 5px 5px 5px #888;
box-shadow: 5px 5px 5px #888;
}
#rezeptformular {
width: 950px;
margin: 3px;
}
#detailinfo {
vertical-align: top;
padding: 5px;
margin: 20px;
}
+5
View File
@@ -9,5 +9,10 @@
<input name="pw" type="password" maxlength="50"/>
<span class="fehlermeldung"></span>
<br>
<img src="captchagenerieren.php" alt="Captcha"><br>
<label class="reg_label">Captcha</label>
<span class="pflichtmarker"> * </span>
<input name="captcha">
<br>
<input type="submit">
</form>
+1
View File
@@ -58,6 +58,7 @@ session_start();
$p = new Plausi();
$anmelden += $p->nutzerdatentest($_POST['userid']);
$anmelden += $p->nutzerdatentest($_POST['pw']);
$anmelden += $p->captchatest($_POST['captcha']);
// Testausgaben für den derzeitigen Stand des Projekts
echo "Die Eingaben: <hr>";
+7
View File
@@ -60,5 +60,12 @@ class Plausi {
}
}
public function captchatest($wert) {
$fehler = 0;
if ($_SESSION['captchacode'] != $wert) {
return ++$fehler;
}
}
}
?>
+8
View File
@@ -0,0 +1,8 @@
<h1>Wählen Sie eine Datei zum Upload aus</h1>
<form action="bildspeichern.php" method="post" enctype="multipart/form-data">
<input name="datei" type="file"><br>
<textarea name="zusatzinfos" cols="20" rows="5">
</textarea>
<br>
<input type="submit" value="Starte Upload">
</form>
+74
View File
@@ -0,0 +1,74 @@
<!DOCTYPE html>
<html>
<head>
<title>Vorschau</title>
<meta charset="UTF-8">
</head>
<body>
<h1>Vorschau</h1>
<?php
class Thumb {
function thumbnail_erstellen() {
$bv = "images";
$vb = "thumb";
$verzeichnis = opendir($bv);
$bilder = array();
while (($datei = readdir($verzeichnis)) !== false) {
if ((preg_match("/\.jpe?g$/i", $datei)) || (preg_match("/\.png$/i", $datei))) {
$bilder[] = $datei;
}
}
closedir($verzeichnis);
$verzeichnis = opendir($vb);
//Schleife, bis alle Files im Verzeichnis ausgelesen wurden
while (($datei = readdir($verzeichnis)) !== false) {
//Oft werden auch die Standardordner . und .. ausgelesen, diese sollen ignoriert werden
if ($datei != "." AND $datei != "..") {
//Files vom Server entfernen
@unlink("$vb/$datei");
}
}
closedir($verzeichnis);
foreach ($bilder as $bild) {
if (preg_match("/\.png$/i", $bild)) {
$b = imagecreatefrompng("$bv/$bild");
} else {
$b = imagecreatefromjpeg("$bv/$bild");
}
$originalbreite = imagesx($b);
$originalhoehe = imagesy($b);
$neuebreite = 120;
$neuehoehe = floor($originalhoehe * ($neuebreite / $originalbreite));
$neuesbild = imagecreatetruecolor($neuebreite, $neuehoehe);
imagecopyresampled($neuesbild, $b, 0, 0, 0, 0, $neuebreite, $neuehoehe, $originalbreite, $originalhoehe);
imagejpeg($neuesbild, "$vb/$bild");
imagedestroy($neuesbild);
}
}
function thumbnail_anzeigen() {
$bv = "thumb";
$verzeichnis = opendir($bv);
while (($datei = readdir($verzeichnis)) !== false) {
if (preg_match("/\.jpe?g$/i", $datei)) {
echo "<a href=''><img src='$bv/$datei' " . "alt='Vorschaubild'></a> ";
}
}
closedir($verzeichnis);
}
}
$obj = new Thumb();
$obj -> thumbnail_erstellen();
$obj -> thumbnail_anzeigen();
?>
</body>
</html>