Wie wähle ich ein Dateiziel in HTML/PHP aus?HTML

HTML-Programmierer
Anonymous
 Wie wähle ich ein Dateiziel in HTML/PHP aus?

Post by Anonymous »

Ich verwende einen HTML-Dateityp, in den der Benutzer Bilder hochladen kann. Ich versuche, den Speicherort der Datei zu ermitteln.

Ich möchte, dass es zur aktuellen Datei (in der sich die PHP-Datei befindet) und dann zur Datenbank\Bilder wechselt.

Ich verwende MySQL zum Hochladen von Daten und habe eine Post-Images-Tabelle, die eine Post-ID (den Fremdschlüssel aus der Post-Tabelle) und einen Bildpfad enthält, der auf die Datenbank/Bilder verweisen sollte, damit ich später darauf zugreifen kann. Wie mache ich das?

Code: Select all

if($_SERVER["REQUEST_METHOD"] == "POST") {
...
$fileUpload = $_FILES["file-upload"];
...
$sqlPostID = "SELECT id FROM posts WHERE title = '$postTitle'";
$result = mysqli_query($conn, $sqlPostID);

if (mysqli_num_rows ($result) > 0) {
$row = mysqli_fetch_assoc($result);
echo "alert(\"$row[id]\");";

$sqlpost_images = "INSERT INTO post_images (post_id, image_path) VALUES ('$row[id]', '$fileUpload')";

try {
mysqli_query($conn, $sqlpost_images);
echo "alert(\"Images uploaded successfully.\");";

} catch (mysqli_sql_exception $e) {
echo "alert(\"Having difficulties connecting to database\");";
}
...
}

Please let me know if you know or need more info. I am trying to learn databases with php and mysql for web development. Thanks

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post
  • Wie wähle ich ein Dateiziel in HTML/PHP aus?
    by Anonymous » » in Php
    0 Replies
    0 Views
    Last post by Anonymous
  • Wie wähle ich ein Dateiziel in HTML/PHP aus?
    by Anonymous » » in MySql
    0 Replies
    0 Views
    Last post by Anonymous
  • Wie wähle ich ein Dateiziel in HTML/PHP aus?
    by Anonymous » » in Php
    0 Replies
    0 Views
    Last post by Anonymous
  • Wie wähle ich ein Dateiziel in HTML/PHP aus?
    by Anonymous » » in HTML
    0 Replies
    0 Views
    Last post by Anonymous
  • Wie wähle ich ein Dateiziel in HTML/PHP aus?
    by Anonymous » » in Php
    0 Replies
    0 Views
    Last post by Anonymous