4 Replies Latest reply on Jul 13, 2017 4:33 PM by GoogleMac

    Using CWP to Display PDF stored in Container Field

    Gregory_Smith

      Hi All,

       

      I have got the hang of using the PHP API to display images stored in a container field per the techniquie described in "FileMaker Server 11 Custom Web Publishing with PHP".

       

      But I am having trouble displaying PDFs stored in a container field. I cannot find any examples which would help me with the PHP code I need. Can anyone point me to some examples?

       

      Thanks,

       

      Greg Smith

        • 1. Re: Using CWP to Display PDF stored in Container Field
          PalmDBS

          In the original PHP file. load the record and use the path of the container field.  Something like:

           

          <?php

          require("dbopen.php");  // my FM connection

          $request = $fm->newFindAllCommand('test');

          $result = $request->execute();

          if(Filemaker::IsError($result)) {$errortext = $result->getMessage(); die($errortext);}

          else {

              $records = $result->getRecords(); if(Filemaker::IsError($record)) {echo "<p />Error: " . $record->getMessage() . "<p />";}

              foreach ($records as $record){

                  echo "<a href='pdfloader.php?path=".urlencode($record->getField("PDFcontainer"))."'>Load PDF</a>";

                  }

              }

          ?>

           

          Create a new PDFloader.php file with the following:

           

          <?php

          header('Content-type: application/pdf');

          require("dbopen.php");  // my FM connection

          echo $fm->getContainerData($_REQUEST['path']);

          ?>

           

          That code above will display your PDF in browser.  You could alternatively use that same getContainerData response to create a physical PDF on the web server filesystem, email it, etc.

           

          Hope this helps.

           

          Mike

          • 2. Re: Using CWP to Display PDF stored in Container Field
            Gregory_Smith

            Thanks Mike. That does help. I had neglected the relevant header in the "PDFloader.php" file.

             

            Greg

            • 3. Re: Using CWP to Display PDF stored in Container Field
              RPaulH

              I hope someone is still alerted to this post. Is the above solution still applicable in FMS14? I cannot get it to work with a container field using FMS external secure storage. I'm reading that currently I need to use getContainerDataURL, but cannot get anything to work with that either. Anyone have some insight? Thanks

              • 4. Re: Using CWP to Display PDF stored in Container Field
                GoogleMac

                I need to be able to download (transfer to external server file system where web app is hosted) PDF files from these container fields. I have had no luck.

                You could alternatively use that same getContainerData response to create a physical PDF on the web server filesystem, email it, etc.

                I have tried a few fopen / get_file_contents options. Is there a recommended approach to this? My goal is to grab a copy using the API so that I can send it in my own email application.