We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16858
    • 58 Posts
    I tell ya ... the more I use MODx, the more I absolutely love it!! Good job developers!

    I have a database that I store image files in. I can decode them easily using an external script, but by doing that I have to have an external database script and the script isn’t directly tied in with MODx.

    Is there a way to decode and display an image directly within MODx? (i.e. I want to pull an image from a database based on an ID number and display that image within my content.

    Thanks for any advice!
      • 22303 MODX Staff
      • 10,725 Posts
      Without knowing more about the script in question, I’d be inclined to say it would be easily converted to a snippet and run within MODx, as long as you make sure to return the proper content type from this MODx document which would be serving images...
        • 16858
        • 58 Posts
        I tried the Snippet route, but was unable to generate the image. Here’s the code:

        <?php

        global $modx;

        if ($_GET) {
        foreach ($_GET as $key => $_value) {
        $key = strtolower($key);
        $value = urldecode($value);
        $_img[$key] = strtolower($value);
        }
        }

        $_table = ’’;

        if (strtolower($_img[m]) == ’events’) {
        $_table = ’modx_events’;
        }

        if ($_table && $_img[id]) {

        $ds = $modx->db->select("image","$_table","id = $_img[id]","","");
        $_image = $modx->db->getRow($ds);

        if ($_image[image]) {

        echo base64_decode($_image[image]);

        }

        }
        ?>