8 Replies Latest reply on Dec 13, 2014 7:10 AM by ebisu

    Trouble in showing images with PHP CWP

    ebisu

      I'm coming across a touble in PHP web publishing with FMS13.


      I'd like to share videos and images in the browser, but only video field works and image cannot be shown.

      Both video and image fields are in external storages, and the connection is SSL except video.

       

      Here are the codes:

      <video src="<?php echo $record->getField('video');echo $fm->getContainerDataURL($video);?>" controls></video>

      <img src="<?php echo $record->getField('image');echo $fm->getContainerDataURL($image);?>">

       

      Although I've never determined varible $video, the video can be played. Strange, but anyway, it's works.

      But the image don't. I checked the source codes in browser. It shows:

      <img src="/fmi/xml/cnt/2014-12-03.jpg?-db=NDocWeb&amp;-lay=Program_web&amp;-recid=6&amp;-field=image(1)">

      Above, "2014-12-03.jpg" is the original image name.


      It I open the image in a new browser, it shows:

      This XML file does not appear to have any style information associated with it. The document tree is shown below.

       

      lol

      I appreciate anybody can help me.


        • 1. Re: Trouble in showing images with PHP CWP
          mikebeargie

          Page 39 of the guide covers displaying images:

          https://fmhelp.filemaker.com/docs/13/en/fms13_cwp_php.pdf

           

          Try this instead:

          echo '<img src="'.$fm->getContainerDataURL($record->getField('image')) .'">';

           

          I'm assuming this is inside a foreach loop where each row is a $record.

          • 2. Re: Trouble in showing images with PHP CWP
            ebisu

            Thank you, Mike.

             

            I tried the codes you suggested, but the image wasn't shown either.

            The html source code returns:


                <img src="localhost/fmi/xml/cnt/2014-12-03.jpg?-db=NDocWeb&-lay=Program_web&-recid=6&-field=image(1)">

             

            , almost same with former one, just "localhost/" is added at the beginning.

            • 3. Re: Trouble in showing images with PHP CWP
              mikebeargie

              we can only really speculate without seeing the rest of your code. Have you read through the guide I linked to? It might provide additional oversight to something you're missing.

               

              Is your CWP PHP code on the same server your filemaker database is hosted on?

              • 4. Re: Trouble in showing images with PHP CWP
                mdenyse

                I would assume you have security on your database, yes? The URL you're using is only likely to work if you have Guest access enabled (something I absolutely do not recommend doing). You need to write your own 'container bridge' PHP script (which uses security) to return the container data. Your <img tag will reference your 'container bridge' PHP script, passing it enough information to specify what container field you're trying to get.

                 

                If you hunt around these forums and the web you'll find examples of how to write a 'container bridge' PHP script.

                1 of 1 people found this helpful
                • 5. Re: Trouble in showing images with PHP CWP
                  mikebeargie

                  There’s also a container bridge demo script in your filemaker server library under:

                   

                  /Examples/PHP/API Examples/containerBridge.php

                  1 of 1 people found this helpful
                  • 6. Re: Trouble in showing images with PHP CWP
                    ebisu

                    I only use one laptop so I think it same hosting.

                    Here is the code. Almost everything is going well such as id, title, and video, except the image.

                     

                    <?php

                    header("Content-Type: text/html; charset = utf-8");

                    ini_set('display_error',1);

                    require_once('FileMaker.php');

                    $fm = new FileMaker('NDocWeb','localhost','web','pass');

                    $record = $fm->getRecordById('Program_web',$_GET['recid']);

                    ?>

                     

                    <!doctype html>

                    <html>

                    <head>

                    <meta charset = "utf-8">

                    <title>NDoc</title>

                    </head>

                    <body>

                    <dl>

                              <dt>ID</dt>

                              <dd><?=$record->getField('_ndocID')?></dd>

                              <dt>Title</dt>

                              <dd><?=$record->getField('title')?></dd>

                              <dt>Video</dt>

                              <dd><video src="<?php echo $record->getField('video');echo $fm->getContainerDataURL($video);?>" controls></video></dd>

                              <dt>Thumbnail</dt>

                              <dd><?php echo '<img src="'.$fm->getContainerDataURL($record->getField('image')) .'">';?></dd>

                    </dl>

                    </body>

                    </html>

                    • 7. Re: Trouble in showing images with PHP CWP
                      ebisu

                      Thank you both. Let me have a check.

                      • 8. Re: Trouble in showing images with PHP CWP
                        ebisu

                        The security you meant is about SSL? Yes, I turned on SSL in FMS13.

                         

                        And I checked "/Examples/PHP/API Examples/containerBridge.php", but shamely I coundn't understand the structure of site very well.

                        I came up with another approach. I got rid of showing image container, and only passed data by base64 text between FM and PHP.

                        It looks like well-done so far, although not so smart.

                        I'm afraid the database file will be fat.  lol