We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17833
    • 28 Posts
    I have a few document attachments stored in a db, and i’m trying to retrieve them. I’ve had success in doing this in straight php but i’m having difficulty now in modx. I’ve tried searching the snippets but havent found anything yet.

    The output that I am getting leads me to think it’s a header issue, but i’m unsure.
    from the snippet:
    $sql = "SELECT * FROM modx_rfi_table WHERE id=6";
    $result = $modx->dbQuery($sql);
    $row = $modx->fetchRow($result);
    $filetype=$row['q_att_type'];
    $filecontent= $row['q_attachment'];
    header("Content-type: $filetype");
    $output = $filecontent;
    return $output;
    

    results:
    ÿØÿë&EPSxœíÁ  ÷OmÀ§% ÿàJFIF``ÿþ&Created by ImageGear, AccuSoft Corp.ÿÀ

    etc.

    any suggestions?
    • I think what you’d want to do is actually create a document in MODx to represent the attachment, set the content type of the document, and then just have the snippet return the content without setting the header (this is already done by MODx).

      I bet someone could come up with a plugin to do this for a single document (i.e. a single MODx doc could return any content/content-type combo via a $_REQUEST param) as well, utilizing the very powerful event system in MODx. (Hint, hint, anyone? anyone?)

      BTW, MODx 1.0+ will also be providing binary content storage in addition to textual content; so images, PDF’s, Word documents, and other types of binary files can be managed with MODx natively, and take advantage of the new features such as content revisioning and rollback, l10n (translations), and i18n (cultures, contexts, context-detection, contextual system/session/user preferences). More on this as we approach 0.9.5 release and reveal the full 1.0 roadmap.