Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    30
    Rep Power
    0

    Storing image path for retrieval and display using php


    hello guys, i have the following code in my html file.

    <tr>
    <td><p align="right">Upload Photo</p></td>
    <td><input type="file" name="prod_photo" id="prod_photo"/></td>
    </tr>

    it has a browse button where i can browse for photos stored in a folder.

    i need to store the photo path in my mysql table so that i can retrieve it later and display it.

    i have another php page which executes to store the data input in the product table.

    am a complete newbie so please help...i have only this part to finish my page
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,850
    Rep Power
    6351
    Which path? The one on the USER'S computer? You can't.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. No Profile Picture
    Dazed&Confused
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2002
    Location
    Tempe, AZ
    Posts
    506
    Rep Power
    128
    Generally speaking the process you're probably after is:

    1. Upload image file through form
    2. Process input and save uploaded file to a web-visible directory
    3. Save that location in your database

    Step #2 is where the meat of it happens and we can help you there, but first and foremost you need to understand the pieces involved.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    30
    Rep Power
    0
    the html tag above let me browse to the folder where the images are stored. i want to store that path in my database table so that when i retrieve the record using mysql syntax, the image is displayed. i need a tutorial to know how to do that or any other help that might be helpful to me....
  8. #5
  9. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,850
    Rep Power
    6351
    You are not understanding...any of what's happening here. Let's talk about Adam and Betty.

    Adam (you) writes a webserver which processes file uploads.

    Betty (your user) uses that website.

    Betty clicks "browse" and browses to a file on her desktop.

    Betty sees "C:\Documents and Settings\Betty\Desktop\Funny.jpg" in the file upload box.

    Betty clicks "submit"

    Funny.jpg and nothing else is transmitted to Adam's server.

    Adam only has access to the file itself, not the path on Betty's computer. Just the file.

    Adam has to store the file on HIS server, and display it from HIS server, not using Betty's computer ever again.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  10. #6
  11. No Profile Picture
    Dazed&Confused
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2002
    Location
    Tempe, AZ
    Posts
    506
    Rep Power
    128
    And even if you're making something strictly for your own personal use and you don't care about Betty, the "file" form field still won't give you the file path you see in the form. It's designed specifically for uploading a file; not providing a local path to a file.

    So what you're trying to do won't work - period.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    30
    Rep Power
    0
    well i sorted it out guys....but now am having a problem to display the photo in a table
    i hv this code and it displays all the required data
    print "<tr>";
    print "<td>" . $result['prod_photo'] ."</td>";
    print "<td>" . $result['prod_name'] . "</td>";
    print "<td>" . $result['prod_brand'] ."</td>";
    print "<td>" . $result['prod_desc'] . "</td>";
    print "<td>" . $result['prod_price'] . "</td>";
    print "<td>" . $result['prod_w_c'] . "</td>";
    print "</tr>";
    }
    print "</table>";

    if i use the code below in an echo, i get the picture that is stored in a folder to display

    '<img src="Images/Products/'*/.$result['prod_photo'].'"/>'

    how do i add that to the previous table display codes so that the picture is displayed now?
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    30
    Rep Power
    0

    Display image in a table


    i hv this code and it displays all the required data when i query the table except the image

    print "<tr>";
    print "<td>" . $result['prod_photo'] ."</td>";
    print "<td>" . $result['prod_name'] . "</td>";
    print "<td>" . $result['prod_brand'] ."</td>";
    print "<td>" . $result['prod_desc'] . "</td>";
    print "<td>" . $result['prod_price'] . "</td>";
    print "<td>" . $result['prod_w_c'] . "</td>";
    print "</tr>";
    }
    print "</table>";

    if i use the code below in an echo, i get the picture that is stored in a folder

    '<img src="Images/Products/'*/.$result['prod_photo'].'"/>'

    how do i add that to the previous table display codes so that the picture is displayed now?
  16. #9
  17. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,850
    Rep Power
    6351
    This is not valid code, so it's not very easy to help you. Show the actual code that displays the image properly.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2006
    Posts
    40
    Rep Power
    9
    Originally Posted by Hance
    i hv this code and it displays all the required data when i query the table except the image

    print "<tr>";
    print "<td>" . $result['prod_photo'] ."</td>";
    print "<td>" . $result['prod_name'] . "</td>";
    print "<td>" . $result['prod_brand'] ."</td>";
    print "<td>" . $result['prod_desc'] . "</td>";
    print "<td>" . $result['prod_price'] . "</td>";
    print "<td>" . $result['prod_w_c'] . "</td>";
    print "</tr>";
    }
    print "</table>";

    if i use the code below in an echo, i get the picture that is stored in a folder

    '<img src="Images/Products/'*/.$result['prod_photo'].'"/>'

    how do i add that to the previous table display codes so that the picture is displayed now?
    To add this '<img src="Images/Products/'*/.$result['prod_photo'].'"/>'
    to the print statement use
    print "<td><img src=\"Images/Products/*/.$result['prod_photo'].\"/></td>";
  20. #11
  21. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    23
    Rep Power
    0
    <img src="Images/Products/'*/.$result['prod_photo'].'"/> write this in td tg of the table.
  22. #12
  23. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,850
    Rep Power
    6351
    Don't create new threads when we're in the middle of a discussion. your threads have been merged.

    Also, don't listen to johnmacd, that's a spam bot or a moron or both.

    Again: the code you were given is not valid and will not work in PHP. Please show the actual code which you claim is showing the image.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    30
    Rep Power
    0
    this code shows the image when the query is performed

    //And we display the results
    while($result = mysql_fetch_array( $data ))
    {
    echo $result['prod_name'];
    echo " ";
    echo '<img src="Images/Products/'.$result['prod_photo'].'"/>';
    echo "<br>";
    }

    i hv the code below and want to display the image in the table row

    while($result = mysql_fetch_array( $data ))
    {

    print "<tr>";
    print "<td>" [I][B]code for display of photo should be here "</td>";
    print "<td>" . $result['prod_name'] . "</td>";
    print "<td>" . $result['prod_brand'] ."</td>";
    print "<td>" . $result['prod_desc'] . "</td>";
    print "<td>" . $result['prod_price'] . "</td>";
    print "<td>" . $result['prod_w_c'] . "</td>";
    print "</tr>";
    }
    print "</table>";
  26. #14
  27. No Profile Picture
    Dazed&Confused
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2002
    Location
    Tempe, AZ
    Posts
    506
    Rep Power
    128
    Originally Posted by Hance
    this code shows the image when the query is performed

    //And we display the results
    while($result = mysql_fetch_array( $data ))
    {
    echo $result['prod_name'];
    echo " ";
    echo '<img src="Images/Products/'.$result['prod_photo'].'"/>';
    echo "<br>";
    }

    i hv the code below and want to display the image in the table row

    while($result = mysql_fetch_array( $data ))
    {

    print "<tr>";
    print "<td>" [I][B]code for display of photo should be here "</td>";
    print "<td>" . $result['prod_name'] . "</td>";
    print "<td>" . $result['prod_brand'] ."</td>";
    print "<td>" . $result['prod_desc'] . "</td>";
    print "<td>" . $result['prod_price'] . "</td>";
    print "<td>" . $result['prod_w_c'] . "</td>";
    print "</tr>";
    }
    print "</table>";
    Then just put it in there...
    PHP Code:
    print "<tr>"
    print 
    '<td><img src="Images/Products/'.$result['prod_photo'].'"/></td>'
    print 
    "<td>" $result['prod_name'] . "</td>"
    print 
    "<td>" $result['prod_brand'] ."</td>"
    print 
    "<td>" $result['prod_desc'] . "</td>";
    print 
    "<td>" $result['prod_price'] . "</td>";
    print 
    "<td>" $result['prod_w_c'] . "</td>";
    print 
    "</tr>"
  28. #15
  29. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,850
    Rep Power
    6351
    Since you didn't show the query, we have to assume that it's the SAME query in both loops. If it is, that solution will work. If it's NOT, then you have to show us both queries.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo