Bilder in einer Datenbank-Tabelle speichern und ausgeben

[Bildschirmfoto]
 Bild in einer Datenbank-Tabelle speichern

Das Hochladen von Bildern über Ajax in die Datenbank und die Anzeige mit PHP ist relativ einfach. Mit dem folgenden PHP-Code lädt der Benutzer die Bilder hoch, die dann sicher in die Datenbank-Tabelle gelangen.

1. Die Bild-Infos und die Bilder in eine DB-Tabelle eintragen

Die DB-Spalte, in der das Bild gespeichert wird, muss den Datentyp: BLOB bzw.: LONGBLOB besitzen (BLOB = Binary Large OBject).

Quelltext:  bilder_datenbank.php AusblendenKopierenLinkZeilen

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
<?php
/*
 * Die Bild-Infos und die Bilder in eine DB-Tabelle eintragen

CREATE TABLE `pictures` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `picture` LONGBLOB NOT NULL,
  `width` VARCHAR(10) COLLATE utf8_unicode_ci NOT NULL,
  `height` VARCHAR(10) COLLATE utf8_unicode_ci NOT NULL,
  `name` VARCHAR(255) COLLATE utf8_unicode_ci NOT NULL,
  `album` VARCHAR(255) COLLATE utf8_unicode_ci NOT NULL,
  `description` TEXT COLLATE utf8_unicode_ci NOT NULL,
  `tags` VARCHAR(255) COLLATE utf8_unicode_ci NOT NULL,
  `date` DATE NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

 */

// Zugangsdaten zur Datenbank
$DB_HOST "localhost"// Host-Adresse
$DB_NAME "test"// Datenbankname
$DB_BENUTZER "root"// Benutzername
$DB_PASSWORT ""// Passwort

/* Zeichenkodierung UTF-8 bei der Verbindung setzen,
 Und eine PDOException bei einem Fehler auslösen. */
$OPTION = [
  
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
  
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
];

try {
  
// Verbindung zur Datenbank aufbauen
  
$db = new PDO(
    
"mysql:host=" $DB_HOST ";dbname=" $DB_NAME,
    
$DB_BENUTZER,
    
$DB_PASSWORT,
    
$OPTION
  
);
} catch (
PDOException $e) {
  
// Bei einer fehlerhaften Verbindung eine Nachricht ausgeben
  
exit('Verbindung fehlgeschlagen! ' $e->getMessage());
}

$output '';
$error = [];

// Angabe der Mimetypen (nur Bilddateien)
$mimeType = [
  
"jpg" => "image/jpeg",
  
"jpeg" => "image/jpeg",
  
"png" => "image/png",
  
"gif" => "image/gif",
  
"webp" => "image/webp",
];

// base64 Header
$base64Header = [
  
'1' => "data:image/gif;base64,",
  
'2' => "data:image/jpeg;base64,",
  
'3' => "data:image/png;base64,",
  
'6' => "data:image/bmp;base64,",
  
'18' => "data:image/webp;base64,",
];

// Daten wurden über das Formular gesendet
if ($_SERVER["REQUEST_METHOD"] == "POST") {

  
// Schleife über alle Dateien
  
for ($i 0$i < count($_FILES["file"]["name"]); $i++) {

    
// Datei wurde ausgewählt
    
if (
      !isset(
$_FILES["file"]["name"][$i]) ||
      empty(
$_FILES["file"]["name"][$i])
    )
      
$error[] = 'Bitte wählen Sie ein Bild aus!';

    
// Fehler beim hochladen
    
if ($_FILES["file"]["error"][$i])
      
$error[] = 'Fehler beim hochladen: ' $_FILES["file"]["error"][$i];

    
// Temporäre Datei wurde hochgeladen
    
if (is_uploaded_file($_FILES["file"]["tmp_name"][$i])) {

      
// Info über die Datei holen
      
list($tmpWidth$tmpHeight$tmpType) = getImageSize($_FILES["file"]["tmp_name"][$i]);
      
$path pathinfo($_FILES["file"]["name"][$i]);
      
$extension strtolower($path["extension"]);

      
// Dateiformat überprüfen
      
if (
        
$tmpWidth < ||
        
$tmpHeight < ||
        !
in_array($extensionarray_keys($mimeType))
      )
        
$error[] = 'Falsches Dateiformat, erlaubt sind nur Bildformate!';

      
// Kein Fehler vorhanden
      
if (empty($error)) {

        
// Base64 Code-String erstellen
        
$code file_get_contents($_FILES["file"]["tmp_name"][$i]);
        
$base64string $base64Header[$tmpType] . base64_encode($code);

        
// Bild für die Ausgabe erstellen
        
$output .= '<figure><img src="' $base64string '" alt="" width="' $tmpWidth '" height="' $tmpHeight '">';

        
// In die DB-Tabelle eintragen
        
$insert $db->prepare(
          
"INSERT INTO `pictures`
            SET
            `picture`     = :picture,
            `width`       = :width,
            `height`      = :height,
            `name`      = :name,
            `album`    = :album,
            `description`    = :description,
            `tags`              = :tags,
            `date`              = NOW()"
        );

        if (
$insert->execute(
          [
            
':picture' => $base64string,
            
':width' => $tmpWidth,
            
':height' => $tmpHeight,
            
':name' => $_FILES["file"]["name"][$i],
            
':album' => $_POST["album"],
            
':description' => $_POST["description"],
            
':tags' => $_POST["tags"]
          ]
        )) {

          
// Dateiname des Bildes
          
$output .= '<figcaption>$_FILES["file"]["name"][$i] . '</figcaption></figure>';
        }
      } else {
        
$output '<p>implode('<br>&#10008; '$error) . '</p>';
      }
    }
  }
  echo 
$output;
  exit;
}
?>
<!DOCTYPE html>
<html lang="de">

<head>
  <meta charset="UTF-8">
  <title>Bilder in die Datenbank eintragen</title>
  <meta name="viewport" content="width=device-width,initial-scale=1.0">

  <style>
    body {
      font-family: Verdana, Arial, Sans-Serif;
      font-size: 1rem;
      background: Whitesmoke;
    }

    h3 {
      font-weight: Normal;
      margin-left: 35px;
    }

    form {
      margin-left: 45px;
    }

    label {
      width: 180px;
      display: Inline-Block;
    }

    input[type="text"] {
      width: 250px;
    }

    textarea {
      width: 440px;
      height: 150px;
      min-width: 440px;
      min-height: 150px;
    }

    :focus-visible {
      outline: Solid 1px lightskyblue;
    }

    button {
      padding: 5px;
      margin: 5px;
    }

    mark {
      background: Transparent;
      color: Red;
    }

    figure>img {
      display: Inline;
      max-width: 100%;
      height: Auto;
      object-fit: contain;
      box-shadow: 0px 0px 4px 2px #8E8E8E;
    }

    .outputstyle {
      width: 550px;
      height: 700px;
      display: Block;
      margin: 0 0 250px 35px;
      padding: 10px;
      overflow: Auto;
      background: White;
      color: Royalblue;
      font-size: 0.80rem;
      text-align: Center;
      border: Solid 1px #BFBFBF;
    }

    img.picture {
      width: 15%;
      background: White;
      padding: 0.5rem;
      outline: Solid Thin Lightgrey;
      background: linear-gradient(#FFFFFF, #E5E5E5);
      box-shadow: 1px 1px 5px #727272;
      display: Inline-Block;
      margin-right: 0.8rem;
      transition: all 0.7s;
    }

    img.picture:hover {
      transform: scale(1.8, 1.8);
    }
  </style>


  <script>
    const XHR = new XMLHttpRequest();

    function request() {
      if (document.getElementById("form").reportValidity()) {
        XHR.open("POST", document.URL, true);
        let daten = new FormData(document.getElementById("form"));
        XHR.send(daten);
        XHR.onreadystatechange = function() {
          if (XHR.readyState >= 4 &&
            XHR.status == 200) {
            document.getElementById("output").innerHTML = XHR.responseText;
            document.getElementById("output").classList.add("outputstyle");
          }
        }
      }
    }

    function selectFiles(event) {
      document.getElementById("preview").innerHTML = "";
      for (var i = 0; i < event.target.files.length; i++) {
        if (event.target.files[i]) {
          var leser = new FileReader();
          leser.addEventListener("load", picLoad);
          leser.readAsDataURL(event.target.files[i]);
        }
      }
    }

    function picLoad(event) {
      var img = document.createElement("img");
      img.setAttribute("class", "picture");
      img.setAttribute("alt", "Bildvorschau");
      img.setAttribute("src", event.target.result);
      document.getElementById("preview").appendChild(img);
    }

    window.addEventListener("DOMContentLoaded", function() {

      document.getElementById("submit").addEventListener("click", request);
      document.getElementById("file").addEventListener("change", selectFiles);

      document.getElementById("reset").addEventListener("click", function() {
        document.getElementById("output").classList.remove("outputstyle");
        document.getElementById("output").innerHTML = "";
        document.getElementById("preview").innerHTML = "";
      });
    });
  </script>


</head>

<body>

  <h3>Bilder in die Datenbank-Tabelle eintragen</h3>

  <form id="form" method="post" enctype="multipart/form-data">

    <p>
      <label for="file">Bilder: <mark>*</mark></label> <input type="file" name="file[]" id="file" multiple="multiple" accept="image/*" required="required">
    </p>

    <div id="preview"></div>

    <p>
      <label for="album">Album: <mark>*</mark></label> <input type="text" name="album" id="album" required="required">
    </p>

    <p>
      <label>Beschreibung:<br>
        <textarea name="description"></textarea>
      </label>
    </p>

    <p>
      <label for="tags">Tags:</label> <input type="text" name="tags" id="tags">
    </p>

    <p>
      <button type="reset" id="reset">Reset</button>
      <button type="button" id="submit">Absenden</button>
    </p>

  </form>

  <div id="output"></div>

</body>

</html>

1. Die Bild-Infos und die Bilder aus einer DB-Tabelle ausgeben

Hier werden alle Bilder ausgegeben die in der Tabelle gespeichert sind. Es erfolgt keine Sortierung oder Limitierung.

Quelltext:  bilder_aus_der_datenbank_ausgeben.php EinblendenKopierenLinkZeilen

2. Die Bild-Infos in eine DB-Tabelle eintragen und die Bilder im Dateisystem ablegen

Die Bilder werden im Dateisystem abgelegt (zum Beispiel im Dateipfad: img/2023/01/).
Es werden also automatisch Unterverzeichnisse für das Jahr und dem Monat erstellt wenn diese nicht vorhanden sind.

➤ Beachten Sie, dass in beiden Beispielen, die Namen der DB-Tabellen gleich sind (`pictures`), diese jedoch unterschiedliche Spaltennamen verwenden.

Quelltext:  bilder_verzeichnis.php AusblendenKopierenLinkZeilen

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
<?php
/*
 * Die Bild-Infos in eine DB-Tabelle eintragen und die Bilder im Dateipfad ablegen.

CREATE TABLE `pictures` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `filename` VARCHAR(255) COLLATE utf8_unicode_ci NOT NULL,
  `path` VARCHAR(255) COLLATE utf8_unicode_ci NOT NULL,
  `width` VARCHAR(10) COLLATE utf8_unicode_ci NOT NULL,
  `height` VARCHAR(10) COLLATE utf8_unicode_ci NOT NULL,
  `album` VARCHAR(255) COLLATE utf8_unicode_ci NOT NULL,
  `description` TEXT COLLATE utf8_unicode_ci NOT NULL,
  `tags` VARCHAR(255) COLLATE utf8_unicode_ci NOT NULL,
  `date` DATE NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

 */

// Zugangsdaten zur Datenbank
$DB_HOST "localhost"// Host-Adresse
$DB_NAME "test"// Datenbankname
$DB_BENUTZER "root"// Benutzername
$DB_PASSWORT ""// Passwort

// Pfad zum Bilderverzeichnis
$IMG_PATH "img/";

// Maximale Länge des Dateinamens
$MAX_FILENAME 65// 65

// Zeitzone setzen
date_default_timezone_set("Europe/Berlin");

/* Zeichenkodierung UTF-8 bei der Verbindung setzen,
 Und eine PDOException bei einem Fehler auslösen. */
$OPTION = [
  
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
  
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
];

try {
  
// Verbindung zur Datenbank aufbauen
  
$db = new PDO(
    
"mysql:host=" $DB_HOST ";dbname=" $DB_NAME,
    
$DB_BENUTZER,
    
$DB_PASSWORT,
    
$OPTION
  
);
} catch (
PDOException $e) {
  
// Bei einer fehlerhaften Verbindung eine Nachricht ausgeben
  
exit('Verbindung fehlgeschlagen! ' $e->getMessage());
}

$output '';
$error = [];

// Angabe der Mimetypen (nur Bilddateien)
$mimeType = [
  
"jpg" => "image/jpeg",
  
"jpeg" => "image/jpeg",
  
"png" => "image/png",
  
"gif" => "image/gif",
  
"webp" => "image/webp",
];

// Daten wurden über das Formular gesendet
if ($_SERVER["REQUEST_METHOD"] == "POST") {

  
// Schleife über alle Dateien
  
for ($i 0$i < count($_FILES["file"]["name"]); $i++) {

    
// Datei wurde ausgewählt
    
if (
      !isset(
$_FILES["file"]["name"][$i]) ||
      empty(
$_FILES["file"]["name"][$i])
    )
      
$error[] = 'Bitte wählen Sie ein Bild aus!';

    
// Fehler beim hochladen
    
if ($_FILES["file"]["error"][$i])
      
$error[] = 'Fehler beim hochladen: ' $_FILES["file"]["error"][$i];

    
// Temporäre Datei wurde hochgeladen
    
if (is_uploaded_file($_FILES["file"]["tmp_name"][$i])) {

      
// Info über die Datei holen
      
list($tmpWidth$tmpHeight$tmpType) = getImageSize($_FILES["file"]["tmp_name"][$i]);
      
$path pathinfo($_FILES["file"]["name"][$i]);
      
$filename $path["filename"];
      
$extension strtolower($path["extension"]);

      
// Dateiformat überprüfen
      
if (
        
$tmpWidth < ||
        
$tmpHeight < ||
        !
in_array($extensionarray_keys($mimeType))
      )
        
$error[] = 'Falsches Dateiformat, erlaubt sind nur Bildformate!';

      
// Kein Fehler vorhanden
      
if (empty($error)) {

        
// Datum erstellen
        
$date date_create('now');
        
$year date_format($date'Y');
        
$month date_format($date'm');
        
$path $year '/' $month '/';

        
// Verzeichnis Jahr erstellen
        
if (!is_dir($IMG_PATH $year)) {
          
mkDir($IMG_PATH $year0777);
        }

        
// Verzeichnis Monat erstellen
        
if (!is_dir($IMG_PATH $year "/" $month)) {
          
mkDir($IMG_PATH $year "/" $month0777);
        }

        
// Dateiname filtern
        
$filename utf8_decode($filename); // UTF-8 decodiert
        
$filename trim($filename); // Whitespace
        
$filename mb_strtolower($filename); // Kleinbuchstaben

        // Hier entsprechende Zeichen und Ersatzzeichen (vom ASCII-Zeichensatz) einfügen
        
$filename str_replace(["ä""ö""ü""ß"" ",], ["ae""oe""ue""ss""_",], $filename);

        
// Angegebene Zeichen durchlassen, alle sonstigen filtern
        
$filename preg_replace("/[^a-z0-9_-]/"""$filename);

        
// Länge des Dateinamens eventuell kürzen
        
$newname substr($filename0$MAX_FILENAME) . "." $extension;

        
// Wenn die Datei vorhanden ist, hänge eine Zahl an den Dateinamen
        // Beispiel: bild002.jpg, bild003.jpg, bild004.jpg
        
if (file_exists($IMG_PATH $path $newname)) {
          
$nr 2// Startzahl
          
do {
            
$newname substr($filename0$MAX_FILENAME) . str_pad($nr3"0"STR_PAD_LEFT) . "." $extension;
            
$nr++;
          } while (
file_exists($IMG_PATH $path $newname));
        }

        if (
move_uploaded_file($_FILES["file"]["tmp_name"][$i], $IMG_PATH $path $newname)) {

          
// In die DB-Tabelle eintragen
          
$insert $db->prepare(
            
"INSERT INTO `pictures`
              SET
              `filename`      = :filename,
              `path`       = :path,
              `width`       = :width,
              `height`      = :height,
              `album`    = :album,
              `description`    = :description,
              `tags`              = :tags,
              `date`              = NOW()"
          );

          if (
$insert->execute(
            [
              
':filename' => $_FILES["file"]["name"][$i],
              
':path' => $path,
              
':width' => $tmpWidth,
              
':height' => $tmpHeight,
              
':album' => $_POST["album"],
              
':description' => $_POST["description"],
              
':tags' => $_POST["tags"]
            ]
          )) {

            
// Bild für die Ausgabe erstellen
            
$output .= '<figure><img src="' $IMG_PATH $path $newname '" alt="" width="' $tmpWidth '" height="' $tmpHeight '">';
            
$output .= '<figcaption>$IMG_PATH $path $newname '</figcaption></figure>';
          }
        }
      } else {
        
$output '<p>implode('<br>&#10008; '$error) . '</p>';
      }
    }
  }
  echo 
$output;
  exit;
}
?>
<!DOCTYPE html>
<html lang="de">

<head>
  <meta charset="UTF-8">
  <title>Bilder in die Datenbank eintragen</title>
  <meta name="viewport" content="width=device-width,initial-scale=1.0">

  <style>
    body {
      font-family: Verdana, Arial, Sans-Serif;
      font-size: 1rem;
      background: Whitesmoke;
    }

    h3 {
      font-weight: Normal;
      margin-left: 35px;
    }

    form {
      margin-left: 45px;
    }

    label {
      width: 180px;
      display: Inline-Block;
    }

    input[type="text"] {
      width: 250px;
    }

    textarea {
      width: 440px;
      height: 150px;
      min-width: 440px;
      min-height: 150px;
    }

    :focus-visible {
      outline: Solid 1px lightskyblue;
    }

    button {
      padding: 5px;
      margin: 5px;
    }

    mark {
      background: Transparent;
      color: Red;
    }

    figure>img {
      display: Inline;
      max-width: 100%;
      height: Auto;
      object-fit: contain;
      box-shadow: 5px 5px 5px #999999;
    }

    .outputstyle {
      width: 550px;
      height: 700px;
      padding: 10px;
      overflow: Auto;
      background: White;
      color: Royalblue;
      font-size: 0.80rem;
      text-align: Center;
      border: Solid 1px #BFBFBF;
    }

    img.picture {
      width: 15%;
      background: White;
      padding: 0.5rem;
      outline: Solid Thin Lightgrey;
      background: linear-gradient(#FFFFFF, #E5E5E5);
      box-shadow: 5px 5px 5px #999999;
      display: Inline-Block;
      margin-right: 0.8rem;
      transition: all 0.7s;
    }

    img.picture:hover {
      transform: scale(1.8, 1.8);
    }
  </style>


  <script>
    const XHR = new XMLHttpRequest();

    function request() {
      if (document.getElementById("form").reportValidity()) {
        XHR.open("POST", document.URL, true);
        let daten = new FormData(document.getElementById("form"));
        XHR.send(daten);
        XHR.onreadystatechange = function() {
          if (XHR.readyState >= 4 &&
            XHR.status == 200) {
            document.getElementById("output").innerHTML = XHR.responseText;
            document.getElementById("output").classList.add("outputstyle");
          }
        }
      }
    }

    function selectFiles(event) {
      document.getElementById("preview").innerHTML = "";
      for (var i = 0; i < event.target.files.length; i++) {
        if (event.target.files[i]) {
          var leser = new FileReader();
          leser.addEventListener("load", picLoad);
          leser.readAsDataURL(event.target.files[i]);
        }
      }
    }

    function picLoad(event) {
      var img = document.createElement("img");
      img.setAttribute("class", "picture");
      img.setAttribute("alt", "Bildvorschau");
      img.setAttribute("src", event.target.result);
      document.getElementById("preview").appendChild(img);
    }

    window.addEventListener("DOMContentLoaded", function() {

      document.getElementById("submit").addEventListener("click", request);
      document.getElementById("file").addEventListener("change", selectFiles);

      document.getElementById("reset").addEventListener("click", function() {
        document.getElementById("output").classList.remove("outputstyle");
        document.getElementById("output").innerHTML = "";
        document.getElementById("preview").innerHTML = "";
      });
    });
  </script>


</head>

<body>

  <h3>Bilder in die Datenbank-Tabelle eintragen</h3>

  <form id="form" method="post" enctype="multipart/form-data">

    <p>
      <label for="file">Bilder: <mark>*</mark></label> <input type="file" name="file[]" id="file" multiple="multiple" accept="image/*" required="required">
    </p>

    <div id="preview"></div>

    <p>
      <label for="album">Album: <mark>*</mark></label> <input type="text" name="album" id="album" required="required">
    </p>

    <p>
      <label>Beschreibung:<br>
        <textarea name="description"></textarea>
      </label>
    </p>

    <p>
      <label for="tags">Tags:</label> <input type="text" name="tags" id="tags">
    </p>

    <p>
      <button type="reset" id="reset">Reset</button>
      <button type="button" id="submit">Absenden</button>
    </p>

  </form>

  <div id="output"></div>

</body>

</html>

2. Die Bild-Infos aus einer DB-Tabelle auslesen und die Bilder vom Dateisystem lesen

Hier werden alle Bilder ausgegeben die in der Tabelle gespeichert sind. Es erfolgt keine Sortierung oder Limitierung.

Quelltext:  bilder_aus_der_datenbank_ausgeben_2.php EinblendenKopierenLinkZeilen

Tipps

Hinzufügen von Wasserzeichen beim hochladen eines Bildes

Vorschaubilder (Thumbnails) erstellen

Bilder in den Browser laden per File API

Grafik als Zeichenkette speichern und wieder als Grafik ausgeben

Bausteine  Alle Anzeigen

Eine zufällige Auswahl von Codeschnipseln aus den Bereichen HTML, CSS, PHP, JavaScript und MySQL.

<area> Areal (Verweis-sensitive Grafik)

CSS - Button Glas-Effekte

PHP - Adventkalender

JavaScript - HTML 5 - Pflichtfeld setzen mit JavaScript

MySQL - Mindestwert einer Spalte ermitteln

Kundenservice
„Hinter jeder guten Homepage steckt immer auch ein guter Service, das Besucher und Kunden rundum betreut.“ Dazu zählen: Beantworten der Emails, Produktbeschreibung, Support, Newsletter, Bei Software - kostenlose Updates. Wichtig sind bei Firmen, Online-Shops die AGB (Allgemeinen Geschäftsbedingungen) und das Impressum.
„Effekte beeindrucken vielleicht einmal - Service und Kundenfreundlichkeit jedoch ein Leben lang“.