Jump to content

Storing image path for retrieval and display using php


Go to solution Solved by ginerjm,

Recommended Posts

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

 

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

first upload the image into a folder, store the image name into the DB.

As the folder will always be the same, you can just define the path 

define("IMG_PATH","http://www.website.com/img_folder_path", true);

... usage

<?php
$file_name = $rs['file_name'];//coming form your DB table

echo '<img src="'.IMG_PATH.$file_name.'" alt="" />';
?>

Besides - the <input type='file' tag will be pointing you at a folder on your client machine, not the server, so you don't want that path.

 

And the prev post was correct.  You never want to store the path in the table UNLESS your table will be hosting files from all over your website.  Usually photos are stored in one folder tree and you can do as the post said - store the root path to that folder and then append any subfolder name to the filename as in:

 

main folder name:  "photos"

 

sub folder names:  "Jim", "Fred", "Linda"

 

Stored in the table would be:

 

"Jim/pic1.jpg", "Jim/pic2.jpg","Fred/hispic.jpg","Linda/herpic.jpg" and so on.

 

If the photos have to be moved, the assumption would be that all the subfolders would just be moved to another parent folder and you just

modify the main folder name stored in your script or in a specific record on your table.

 

Remember - that code you showed us is to browse for files on the client.  If you want to give the user something to browse the files on the server (ie, in your db), you need to do something else.

hmmmm ok. lets say the photo folder is stored on my pc and am uploading it from there itself when i do the browse. how can i store that path so that when i perform a mysql query i can retrieve the photo to be displayed in a grid view?

if you don't want to upload the image because it's already there, just use the browse field form option but do nothing with the image itself but just grab the name of the image and insert it into the DB

this will be your form...

<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
</form>

php code for getting the file name...

//GRAB THE FILE NAME
$imgName = $_FILES["file"]["name"];

... and store it into the DB without the uploading feature :)

thnx for your help my friend and what abt the code in the upload_file.php? what code to write in there so that the path is stored in the table column and i can retrieve it later wen doing my query so that the image is displayed....

  • Solution

Are you all set with this question?  I can't tell from the posts so far.

 

If not, I have questions.  Like - are you uploading images or not?  Kinda sounds like you are not which means how do you expect to display them?  AFAIK you can't keep them on your pc and display them on your webpage.  The pic files need to be stored on your server and then your script creates html tags that point to the folder holding your images and looks up any data about the pics in your db, using the filename as the lookup value.

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.