We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29774
    • 386 Posts
    therebechips Reply #1, 18 years ago
    Hi, hope someone has tried this before. I’m trying to get a doument to represent a pdf file.

    I’ve created a TV called ’File’ that allows a filepath to be associated with a document. I have set the document content-type to ’application/pdf’ and the content-disposition to ’attachment’ in the page settings tab. What I’m not clear about is how to output the file to the page, given that I can’t just output the headers directly as the page is parsed by modX. So I wrote this snippet to open the file and just echo the file data:

    global $base_path;
    
    /* Parameters */
    $file = isset($file)? "$file" : '';
    if ($file != "") {
       $filename = $base_path.$file;
    }
    
    $dataFile = fopen( $filename, "r" ) ;
    
    if ( $dataFile ) {
       while (!feof($dataFile)) {
           $buffer = fgets($dataFile, 4096);
           echo $buffer;
       }
       fclose($dataFile);
    } else {
       return("fopen failed for $filename");
    }
    return;


    EDIT: Added code tags

    But unsurprisingly, it mangles the modX document parser.

    One solution would be to just use modX->SendRedirect(’$filePath’) so that the page just redirects to the file, but that seems somehow clumsy to me. It makes me think I might be missing something obvious here? Is there a simple way of representing files in the document tree?

    Can anyone enlighten me?

      Snippets: GoogleMap | FileDetails | Related Plugin: SSL
    • This is what web links are for...just create a New Web Link and set the URL to find the file.
        • 29774
        • 386 Posts
        therebechips Reply #3, 18 years ago
        My content authors would struggle with a weblink because they would have to upload the file in the file manager, copy the link and paste it in the field. That’s too difficult, plus I don’t really want them to give them access to the file manager where they could potentially mangle stuff!

        It would be better to have the Weblink field open up the FCK stand-alone resource browser, so that they could simply upload the file (or choose an existing one) and the link would be set dynamically. I will hack this into the manager.
          Snippets: GoogleMap | FileDetails | Related Plugin: SSL
        • Well, what you’re really talking about here is document management (over and above content management), something we will be exploring in much more detail in 1.0. There are some at least rudimentary snippets in this regard for having users upload files from the front end; DocMan comes to mind. And in regards to hacking the manager, I believe you might be able to do this without going to that extreme, by using a plugin, creating a separate module for your management interface for the the documents, or by creating front-end interfaces (i.e. using quick-edit in conjunction with TV’s to allow uploads).
            • 29774
            • 386 Posts
            therebechips Reply #5, 18 years ago
            Yes, you’re right of course. In fact I’ve written all sorts of file management scripts in the past where the data is stored in the db rather than the fileserver, which has the advantage of allowing one to restrict access to files to defined groups of users. If I get a spare few hours I’ll write a module. However, in this instance I think I’ll hack the manager as time is tight and it will only take a few lines of javascript to invoke the FCK resource browser for the field.

            Many thanks for your help.
              Snippets: GoogleMap | FileDetails | Related Plugin: SSL