Jump to content

displaying image


mike6256

Recommended Posts

Hi all

I need some help with a code that will display specific info and image from my DB. The code I have will display all DB info with a download link for each result. This would work if it only displayed a single search result. Any help would be appreciated.

the code follows:

 

<?php

# Connect to the database

$dbLink = mysqli_connect("127.0.0.1", "user", "pwd", "dbName");

if(mysqli_connect_errno()) {

    die("MySQL connection failed: ". mysqli_connect_error());

}

 

# Query for a list of all existing files

$result = mysqli_query($dbLink, "SELECT FileID, FileName, FileMime, FileSize, Created FROM FileStorage");

 

# Check if it was successfull

if($result) 

{

 

    # Make sure there are some files in there

    if(mysqli_num_rows($result) == 0) {

        echo "<p>There are no files in the database</p>";

    }

    else

    {

        # Print the top of a table

        echo "<table width='100%'><tr>";

        echo "<td><b>Name</b></td>";

        echo "<td><b>Mime</b></td>";

        echo "<td><b>Size (bytes)</b></td>";

        echo "<td><b>Created</b></td>";

        echo "<td><b> </b></td>";

        echo "</tr>";

 

        # Print each file

        while($row = mysqli_fetch_assoc($result))

        {

            # Print file info

            echo "<tr><td>". $row['FileName']. "</td>";

            echo "<td>". $row['FileMime']. "</td>";

            echo "<td>". $row['FileSize']. "</td>";

            echo "<td>". $row['Created']. "</td>";

 

            # Print download link

            echo "<td><a href='get_file.php?id=". $row['FileID'] ."'>Download</a></td>";

            echo "</tr>";

        }

 

        # Close table

        echo "</table>";

    }

 

    # Free the result

    mysqli_free_result($result);

}

else 

{

    echo "Error! SQL query failed:";

    echo "<pre>". $dbLink->error ."</pre>";

}

 

# Close the mysql connection

mysqli_close($dbLink);

?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/146675-displaying-image/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.