Jump to content

I need to display an image from my FTP using a database entry result (php & mysql)


justin007

Recommended Posts

I am looking for some guidance before i attampt to code the following.

 

 

The Brief:

I have a MySQL database of music, one of the columns is called "albumart", within this entry is a file name i.e. "picture.jpg".

 

This entry is not a link... just a file name.

 

I would like to display picture.jpg onto my website.

 

The picture is stored in a specific location on the server.

 

This is what i think i need to do:

 

Call the "albumart" columns most recent entry into a variable (i think) , then ask PHP to go and find the "file name" from a specific location (on the server) add it to another variable (i think) and then display it on screen.

I hope this makes sense...

 

although i understand the basic concept i am unsure where to start when it comes to linking the two bits of code together

 

much respect...

 

justin..

 

Link to comment
Share on other sites

You would need to have the images stored in a folder that is accessable through the webserver software using a path. if this is a fixed location then you can just hard code it, if it is dynamic then you really should be storing it in the database attached to the image.  What is your full current setup?

Link to comment
Share on other sites

Hi Muddy_

 

I have mysql, php, apache all setup and running on a localhost enviroment.

 

All the images will be stored on my server (in the htdocs folder) therefore a fixed location.

 

The database stores the filename of each picture but nothing else.

 

thanks...

 

Justin.

Link to comment
Share on other sites

well if it's in the root htdocs folder then all you need to do is get the file names from the database and use them in the src of the image elements of the page with a leading "/" something a bit like the following

<?php
$con = new PDO("mysql:host=localhost;dbname=yourDBname","username", "password");
$sql = SELECT name NAME images;
$con->execute($sql);
$result = $con->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $row){
  echo "<img src=\"/{$row['name']}\" alt=\"\" />";
}
?>

That is over simplified but shouldn't be a million miles away.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.