TechnoDiver Posted July 14, 2021 Share Posted July 14, 2021 I hope this is the appropriate forum for this question. If not I apologize I'm trying to put a locally stored pic in a phpmyadmin db table. Not upload it to the db but put the path in the text field of the profile pic category. I can paste the link to a web photo in the text field area and it works fine, so my script is working, but for some reason I get the broken photo icon and not the photo when I use the local path in the same way that a web address works. I've used /opt/lampp/htdocs/[site name]/img/name.png and that doesn't work. I've tried localhost/[site name]/img/name.png and that doesn't work either. Some research got me to set the type as LONGBLOB and store the photo in the db, but that doesn't work either. Is there a special format for local paths that needs to be used? I can't find anything about that if there is. like I said - a url to an online photo works but I can't get a local path to work. Any guidance? TIA Quote Link to comment Share on other sites More sharing options...
kicken Posted July 14, 2021 Share Posted July 14, 2021 A local file reference needs to use a file:// url, not just the local path. However, a webpage served via http(s) cannot attempt to load a local file as a resource, the browser won't allow it as a security measure. What are you trying to do that you want to be able to use local file paths? Quote Link to comment Share on other sites More sharing options...
TechnoDiver Posted July 14, 2021 Author Share Posted July 14, 2021 (edited) Hi kicken, thanks for the response. I'm building a registration form and writing the user class right now. Eventually the photos will be uploaded to the db but right now it's just my info in the db so I can experiment with my code. I'm to the point I wanted to play around with the profile pic and simply wanted to insert one I have saved locally into my local phymyadmin as I haven't scripted the downloader yet. Nothing I do will display this image in the page, just the broken image icon. Again this is all in local development, I'm using XAMPP so the page isn't being served via https. I've tried file://localhost/[site name]/img/name.png and that doesn't work either, no problem if I use a web image url in the db (https://......). I don't get it. Maybe it's late and I'm being dumb. but I can't get this photo to show. The image is obviously stored in the site directory on XAMPP - /opt/lampp/htdocs/[site name]/img/[image name].. Edited July 14, 2021 by TechnoDiver Quote Link to comment Share on other sites More sharing options...
requinix Posted July 14, 2021 Share Posted July 14, 2021 Take it one step at a time. All you need to store in the database is a partial file path. If you know that the file is going to be in the img/ directory then you don't need to store "img/" in it - let alone "/opt/lampp" and everything else. Once you have that file path, the "src" you give to the <img> has to be the right relative URL to access the image. If your files are stored in /opt/lampp/htdocs/<site>/img/<name> and your website root is /opt/lampp/htdocs/<site> then your image would be <img src="/img/<?= $the_partial_image_path_which_weve_decided_is_just_the_name_part ?>"> Quote Link to comment Share on other sites More sharing options...
TechnoDiver Posted July 14, 2021 Author Share Posted July 14, 2021 requinix, thank you. I was just coming back to here to post that I figured it out. It was indeed that I did not need the /opt/lampp/htdocs/ segment of the path. Thanks again to you and kicken for your responses Quote Link to comment Share on other sites More sharing options...
kicken Posted July 14, 2021 Share Posted July 14, 2021 49 minutes ago, TechnoDiver said: Again this is all in local development, I'm using XAMPP so the page isn't being served via https. http(s) means http or https, and you are certainly using one or the other if your PHP code is being processed. If your page is loaded via http://... or https://... you cannot use a file:// reference in it, the browser simply will not allow it. Your image must be accessed via http as well, so you need to generate the appropriate URL to put into your image tag. Quote Link to comment 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.