Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/313386-photos-in-phpmyadmin/
Share on other sites

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?

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 by TechnoDiver

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 ?>">

 

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.

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.