Support » Plugin: WP Data Access » Get image-path from Image-Number generated through Plugin

  • Resolved chiaraarmbruster

    (@chiaraarmbruster)


    Hello Peter,

    I made quite some progess with my web-application. Your explanations helped me very much.
    As I am now able to show data from my database, I would like to display a image, I uploaded via a project page.
    I saw in the database that the image is stored as a number like “355”. How can I get the image-path with this information? I guess the path-info is stored in a wp-data-access-table or something and I have to do another sql-statement to get the path?

    Actually, I am generally not very happy with the way wordpress stores images. Is there a possibility to change the image upload in the project pages to own folders on the server? Or is this a major programming task and nothing for amateurs like me? πŸ˜€

    Thank’s for your help!

    Wish you a great day and weekend πŸ™‚
    Chiara

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author Peter Schulz

    (@peterschulznl)

    Hi Chiara,

    The plugin supports WordPress media library integration in the dashboard only. Which means, you can add (change, remove) images from your WordPress library to your app in the dashboard, but not on a webpage. Images added in the dashboard will be shown on your webpage, but you cannot add, change or remove an image on a webpage.

    Images are indeed stored as integers. These integers represent the media id in the WordPress library. Media data can be retrieved with WordPress function wp_get_attachment_url(). If you want to have a look at how this works, please check out class WPDA_Simple_Form_Item_Media.

    You can add your own image functionality. You could also create an add-on for the plugin to support the WordPress media library in the front-end? πŸ™‚ I think it is quite some work, but I guess it’s possible. You don’t seem to be an amateur to me. And you are quite persistent! πŸ˜‰

    The question is: what are your functional requirements?

    Have a nice weekend,
    Peter

    Good morning Peter,

    actually I want to display the pictures in the front-end (no editing in front-end needed), but not via a table like the wp data access publisher enables. I’m trying to programm a php-template-doc to view the entries of one single table row where I see the picture on the left and then have other text items next to it and so on. That’s why I needed to understand how to get from the Image-Number stored to the Image-URL.

    For the Image-Upload and new entries in my table I use wp data access project pages in the backend. That works quite fine, but I would love to have the possibility to use my own folders. For each product I want to display, there are several pictures and because there will be several people uploading and adding new data, it would help much, if we would have a folder for every product. The storing from wordpress with year and month isn’t quite appropriate for that extend of images.
    Unfortunately I haven’t yet found a good plugin, doing the folders directly in the uploading box. Mostly you have to upload and then change the image-directory of these.

    Another possibility to handle this, would be to only use url-paths to the pictures when adding a new data via the wp data access project page. But then I don’t see the picture and couldn’t directly control the upload/addition of it to the product. So, I would always have to go to my front-end and search for the product and then see if the picture is really stored there.

    I’m not quite sure yet, what would be the best way to handle this.
    Maybe I have to make a compromise and use the wordpress media library as it is, and when there comes a situation I have to switch from wordpress to something else or offline I have to write a script, which somehow changes the numbers to paths for each picture in my database.
    What would you do in my position?

    For now I’m going to work on the front-end page to display my product. But at some point I have to decide how to cope with the storing of the pictures.

    Many greetings,
    Chiara

    Plugin Author Peter Schulz

    (@peterschulznl)

    Hi Chiara,

    I have been thinking about doing something similar. My idea was to write images to a specific plugin folder and write a proxy like “getimage.php” which grabs the file from the folder and sends it to the browser. Your HTML would look like this:
    <img src="/your-path/getimage.php?id=123">

    These images are not directly available from a public URL. A user needs to know the id. This gives you the possibility to limit access to your images. That was my goal! On the downside images are not indexed on search engines. Which might be an interesting feature for a profile page for example.

    It depends on your requirements. If you want images to be indexed, I would advice to use the WordPress media library. If you want to be able to limit access, a proxy might be a good idea.

    What will you do…? πŸ™‚

    Best regards,
    Peter

    I think the idea is really good to use a getimage.php document to get pictures from a specific folder. But then my problem would be, how to connect the correct picture (image-id or url) in the project page when I add a new data row.
    So I would need to edit the plugin somehow to upload the pictures to my folder, right? Somehow I would have to get the right connection between the project-page-editing and the diplay in the front-end of the pictures.

    Also, I’m not yet sure how to give a picture an image-id or read the value. But i guess there’s lots of explanation how this works when I search online for it. πŸ™‚

    The indexing of images is not that important for my project, because the webpage is rather for people knowing the page/project.

    Best regards,
    Chiara

    Plugin Author Peter Schulz

    (@peterschulznl)

    Hi Chiara,

    You could create your own table with an image id and a file name. To generate a unique file name you can just use a combination of the current date and time + a random number. However, any complexity added, increases the chance of getting errors. So keeping it simple might be a good idea! πŸ™‚ Maybe you can start with the WordPress media library and add your own logic later…

    Thank you for your nice words in your rating! πŸ™‚

    Best regards,
    Peter

    Hello Peter,

    tonight I thought about the possibility to add my own php-Skript after the addition/change of data in the project pages. There I could just copy the image from the media library to a self-generated folder where I store all pictures per product.
    The question then is, if I add a new column in each table with pictures for the “copied” pictures, use your suggested image-table (could there also add the wordpress media-id) or if I just have the saved pictures stored somewhere without DB logic.

    On the other hand I could also just use wp_get_attachment_url() as soon as I really have to change the environment or need the pictures somewhere else then wordpress.

    I think I’m going to put that option at the end of my web application development and firstly do the really important pages and functions πŸ˜€

    Have a nice day,
    Chiara

    Hi Peter,

    I’m currently trying to get the css-Element for a image in the data entry project page (backend). When I add a big picture I want that it is only displayed with max height of 200px, so that it isn’t displayed over the whole screen. Could you please help me with the Element?
    I tried things like you did in the styling-help for wpdiehard-pages:
    – table.wp-list-table tbody tr td div.img {}
    – div#id_of_div {}
    and so on. But nothing works out.

    Thank you very much!
    Chiara

    Plugin Author Peter Schulz

    (@peterschulznl)

    Hi Chiara,

    The plugin adds a class (= column name) to each item in the list. Usually the easiest way is to use this class name. Something like this:

    td.image_column_name img {
    width: 200px;
    height: 200px;
    }

    Where image_column_name is the name of your column. Does this help?

    Thanks,
    Peter

    chiaraarmbruster

    (@chiaraarmbruster)

    Hi Peter,

    that firstly didn’t work out. Now I found the problem.
    In WPDA_Data_Tables.php Line 571 the height and width of the image is set according to the metadata of it directly to the element, so that custom css doesn’t work.

    I now just edited this, so that the image isn’t sized to it’s metadata and the custom height works fine now.

    Best regards,
    Chiara

    Plugin Author Peter Schulz

    (@peterschulznl)

    Great you fixed it! 😊 Can you send me your edit? πŸ˜‰

    Can I close this topic?

    Thanks,
    Peter

    Hi Peter,

    sure WPDA_Data_Tables.php from Line 570:

    $image_src      .=								
    //'<img src="' . $url . '" style="width:' . $image_metadata['width'] .								
    //'px;height:' . $image_metadata['height'] . 'px;">';								
    '<img src="' . $url . '">';'
    

    (the old code is as comment now and the new code is the last line.)

    Yes you can close the topic πŸ™‚

    Best Regards,
    Chiara

    Plugin Author Peter Schulz

    (@peterschulznl)

    Thank you Chiara! πŸ™‚

    I’ll see if I can use your code and add a setting where developers can chose to auto style or style themselves.

    Have a nice wekeend,
    Peter

Viewing 12 replies - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.