Ankündigung

Einklappen
Keine Ankündigung bisher.

Dropdown Menü Bilder auswählen

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Dropdown Menü Bilder auswählen

    Hallo,
    Da ich zurzeit noch ein Anfänger bin was Programmieren betrifft würde ich mal eure Hilfe brauchen.
    ich bin zurzeit an einem "Controlling" Tool für gewisse Websiten wo einfach gecheckt wird ob sie erreichbar sind oder eben nicht.
    Es ist schon möglich auf dieser Seite Bilder hochzuladen die dann in der MySQL Datenbank gespeichert werden. Jetzt versuche ich gerade bei den Servern ein Dropdown Menü zu erstellen wo man aus allen hochgeladenen Bilder eines Auswählen kann um es sozusagen als Profilbild hinzuzufügen.


    UPLOAD FUNCTION:
    PHP-Code:
    <?php
    // Include the database configuration file
    include 'dbConfig.php';
    $statusMsg '';

    // File upload path
    $targetDir "uploads/";
    $fileName basename($_FILES["file"]["name"]);
    $targetFilePath $targetDir $fileName;
    $fileType pathinfo($targetFilePath,PATHINFO_EXTENSION);

    if(isset(
    $_POST["submit"]) && !empty($_FILES["file"]["name"])){
    // Allow certain file formats
    $allowTypes = array('jpg','png','jpeg','gif','pdf');
    if(
    in_array($fileType$allowTypes)){
    // Upload file to server
    if(move_uploaded_file($_FILES["file"]["tmp_name"], $targetFilePath)){
    // Insert image file name into database
    $insert $db->query("INSERT into images (file_name, uploaded_on) VALUES ('".$fileName."', NOW())");
    if(
    $insert){
    $statusMsg "The file ".$fileName" has been uploaded successfully.";
    }else{
    $statusMsg "File upload failed, please try again.";
    }
    }else{
    $statusMsg "Sorry, there was an error uploading your file.";
    }
    }else{
    $statusMsg 'Sorry, only JPG, JPEG, PNG, GIF, & PDF files are allowed to upload.';
    }
    }else{
    $statusMsg 'Please select a file to upload.';
    }

    // Display status message
    echo $statusMsg;
    ?>

    <?php
    // Include the database configuration file
    include 'dbConfig.php';

    // Get images from the database
    $query $db->query("SELECT * FROM images ORDER BY uploaded_on DESC");

    if(
    $query->num_rows 0){
    while(
    $row $query->fetch_assoc()){
    $imageURL 'uploads/'.$row["file_name"];
    ?>
    <img src="<?php echo $imageURL?>" alt="" />
    <?php }
    }else{ 
    ?>
    <p>No image(s) found...</p>
    <?php ?>
    dbConfig.php:
    PHP-Code:
    <?php
    // Database configuration
    $dbHost "localhost";
    $dbUsername "root";
    $dbPassword "";
    $dbName "login";

    // Create database connection
    $db = new mysqli($dbHost$dbUsername$dbPassword$dbName);

    // Check connection
    if ($db->connect_error) {
    die(
    "Connection failed: " $db->connect_error);
    }
    ?>
    Wie genau mache ich jetzt das Dropdown Menü um Bilder aus der Datenbank hinzuzufügen?
    LG

  • #2
    Habs jetzt geschafft die Namen der Bilder in nem Dropdown anzeigen zu lassen, jedoch wird mir das Bild ansich noch immer nicht angezeigt.
    Kann mir wer helfen?

    PHP-Code:
    <?php

    include 'dbConfig.php';
    ?>


    <select type="text" class="form-control" id="location" name="location"/>
    <?php
    $ergebnis 
    mysqli_query($db"SELECT * FROM images");
    while(
    $row mysqli_fetch_object($ergebnis))
    {
    echo 
    "<option value=/"$row->file_name .">" $row->file_name "</option>";

    }



    ?>
    </select>

    Kommentar


    • #3
      Ein <option>-Element kann standardmässig keine Bilder darstellen. Da musst du Umwege gehen.

      https://www.google.com/search?ei=flQ...71.WsZ6wmSap6A

      Kommentar


      • #4
        so?

        echo "<img src='http://localhost/uploadtest/uploads/". $row->file_name . "/>";

        Kommentar


        • #5
          Bevor du PHP programmierst, solltest du dich erstmal mit HTML befassen. Baue eine Lösung alleine in HTML ohne PHP. Und wenn diese funktioniert, setze sie in PHP um.

          Kommentar

          Lädt...
          X