hance2105 Posted June 14, 2013 Share Posted June 14, 2013 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.... Quote Link to comment https://forums.phpfreaks.com/topic/279148-storing-image-path-for-retrieval-and-display-using-php/ Share on other sites More sharing options...
louie35 Posted June 14, 2013 Share Posted June 14, 2013 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="" />'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/279148-storing-image-path-for-retrieval-and-display-using-php/#findComment-1435950 Share on other sites More sharing options...
ginerjm Posted June 14, 2013 Share Posted June 14, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/279148-storing-image-path-for-retrieval-and-display-using-php/#findComment-1435957 Share on other sites More sharing options...
hance2105 Posted June 14, 2013 Author Share Posted June 14, 2013 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? Quote Link to comment https://forums.phpfreaks.com/topic/279148-storing-image-path-for-retrieval-and-display-using-php/#findComment-1435993 Share on other sites More sharing options...
louie35 Posted June 14, 2013 Share Posted June 14, 2013 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 DBthis 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 Quote Link to comment https://forums.phpfreaks.com/topic/279148-storing-image-path-for-retrieval-and-display-using-php/#findComment-1435996 Share on other sites More sharing options...
hance2105 Posted June 14, 2013 Author Share Posted June 14, 2013 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.... Quote Link to comment https://forums.phpfreaks.com/topic/279148-storing-image-path-for-retrieval-and-display-using-php/#findComment-1435999 Share on other sites More sharing options...
louie35 Posted June 14, 2013 Share Posted June 14, 2013 Write and SQL INSERT query http://www.w3schools.com/php/php_mysql_insert.asp Quote Link to comment https://forums.phpfreaks.com/topic/279148-storing-image-path-for-retrieval-and-display-using-php/#findComment-1436002 Share on other sites More sharing options...
Solution ginerjm Posted June 15, 2013 Solution Share Posted June 15, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/279148-storing-image-path-for-retrieval-and-display-using-php/#findComment-1436168 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.