SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Oct 2002
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Retrieving images from directory

    Hello,
    I am a php newbie that is just learning web design on my own time. I am putting together a db to store my dvd's in so I can learn this whole process. This is something that I maintain and do not have a process for others to upload. I have a simple form that uploads all the info about the dvd, including an image name (titans.jpeg). I have uploaded all of the images into a directory (images/dvds/). What I am trying to figure out, is to pull the correct image out of the directory and display it on a page when a user selects that movie title. Any ideas would be appreciated.

    Thanks

  2. #2
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would just store the name "titans.jpeg" in the database Then you can refer to it straight into your code without anything tricky happening.

    I'm presuming the rest of your information is pulled from a database?

  3. #3
    SitePoint Member
    Join Date
    Oct 2002
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by platinum
    I would just store the name "titans.jpeg" in the database [img]images/smilies/smile.gif[/img] Then you can refer to it straight into your code without anything tricky happening.

    I'm presuming the rest of your information is pulled from a database? [img]images/smilies/smile.gif[/img]

    Yes, all of the info about the dvd is coming from a database and the image name is stored there as well. What I do not know is how to pull it all together to get the picture to display. Should I store the path of the directory in a variable? Then how would I get the path and image linked together to get the image? Do I have to use some kind of method to read from the directory?

    Thanks for the help.

  4. #4
    SitePoint Member
    Join Date
    Oct 2002
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by platinum
    I would just store the name "titans.jpeg" in the database [img]images/smilies/smile.gif[/img] Then you can refer to it straight into your code without anything tricky happening.

    I'm presuming the rest of your information is pulled from a database? [img]images/smilies/smile.gif[/img]

    Yes, all of the information is coming from a database including the image name. I just do not know how to refer to it show it will pull and display the actual image from the directory. Is there some kind of function that I have to use to get something out of a directory? would you store the path in a variable to make refering to it easier?

    Thanks

  5. #5
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can just refer to it like:

    Or am I missing a vital point here?

    PHP Code:
    <?
      $imagename 
    $row['imagename'];
    ?>
    <img src="images/<?=$imagename?>" />

  6. #6
    SitePoint Member
    Join Date
    Oct 2002
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for all your help. I am actually storing the complete link in the database now. So in my table, for the column 'imagename' I am storing images/dvds/image.jpeg. I works like a charm. Thanks again for your help.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •