7 Replies Latest reply on Dec 8, 2016 6:10 PM by FredBloggs

    Accessing data in a container field with external storage via php

    pewi

      Hi,

       

      I am trying to load images stored in a container field with external storage (open) into my website using php. Data from ordinary fields are presented nicely but the image will not load until I enter user credentials for a user with full access to FM database. After I enter these information the browser remembers the credentials for the current session.

       

      For the casual internet user I use a limited privilege set and the user credentials for this account are written into the php-script. The privilege set has view access to all fields in the table where the container field resides. Even if I change the credentials in the php-script to an account with full access privileges I am still foreced to enter the credentials again, when I try to load the images.

       

      There seems to be two problems here:

       

      1) Which privileges are missing for the internet user?

       

      2) Why is it nesesary to type in user credentials, when these are allready within the php-script?

       

      Does anyone know, what I am missing?

       

      Kind regards

       

      Peter

        • 1. Re: Accessing data in a container field with external storage via php
          LyndsayHowarth

          I'm guessing you are on Windoze... with IIS as a server...?

           

          If so...this is something to do with the Anonymous user and their privileges. I never quite figured out what and my client... seeing it work just fine on my Mac server... bought a Mac for me instead!

           

          - Lyndsay

          • 2. Re: Accessing data in a container field with external storage via php
            LyndsayHowarth

            I mean the Anonymous user of the web & OS... not FM.

            • 3. Re: Accessing data in a container field with external storage via php
              databuzz

              Hi Peter,

               

              Have a look at this thread:

               

              https://fmdev.filemaker.com/thread/72864

               

              I'm pretty sure the answer is in there. You will most likely need to use a "containerBridge.php" file that you include in your current PHP page - this resolves the issue of being prompted for credentials.

               

              HTH,

              Andrew

               

              FileMaker 13 Certified Developer

              Databuzz

              - - - - - - - - - - - - - - - - -

              Phone: +61 2 9484 6565

              Mobile: +61 418 468 103

              Email: andrew@databuzz.com.au

              http://www.databuzz.com.au

              1 of 1 people found this helpful
              • 5. Re: Accessing data in a container field with external storage via php
                pewi

                I think I read about containerBridge.php somewhere. Now I find it mentioned in the examples file on FM Server. I'll dive in to the issue later and see if I can get it working. Thaks for your advice.

                • 6. Re: Accessing data in a container field with external storage via php
                  TimDietrich

                  Peter --

                   

                  I think a number of us have been burned by this while working on CWP solutions. It can be very frustrating and confusing.

                   

                  From what I've been able to tell, the problem comes up when you use getContainerDataURL to generate a URL to publish a container's contents. The URL that it generates bypasses PHP and goes directly to FMS (Tomcat, I believe). As a result, if a user ries to use that link, FMS doesn't "know who the user is" because the request isn't coming through the API. That's why the user is asked to authenticate.

                   

                  There's a project that we're working on called FMEasyWeb (http://fmeasyweb.com) that handles container images in a different way. Instead of generating a URL that points back to the container, it Base64 encodes the image and puts it directly into the "img" tag. It is extremely efficient, and from our testing, it works with all of the possible container configurations (including external secure and open storage). I like this technique so much that I'm planning to add support for it in the next release of FMWebFrame (http://fmwebframe.com).

                   

                  I'm including a code snippet from EasyWeb below, and you might be able to modify and use it. Note that it still needs some work. It is "smart enough" to determine that a container is holding an images versus other file types, but not yet smart enough to generate links instead of image tags in those cases.

                   

                  Anyway, I hope it helps. If you have questions about it, please let me know.

                   

                  -- Tim

                   

                   

                  Notes:

                  • Sorry for any weird spacing issues here. I tried to paste this in and it looks odd.

                  • $field -> getName() is the container field's name. You can hard code it if necessary.

                   

                   

                  // Get the text representation of the container.

                  // Example: /fmi/xml/cnt/Lego%201.png?-db=FMEZWeb_Contacts&-lay=FMEasyWeb%20-%20Form%20-%20Contacts&-recid=504&-field=Photo%20Container(1)

                  $container_field_as_text = $record -> getField ( $field -> getName() );

                   

                   

                  // Split the value into an array so that we can isolate the file name.

                  $container_field_array = explode ( '?', $container_field_as_text );

                   

                   

                  // Get the file name (the first element of the "container_field_array" array).

                  $filename = $container_field_array[0];

                  $filename = str_replace ( '/fmi/xml/cnt/', '', $filename );

                  $filename = urldecode ( $filename );

                   

                   

                  // Explode the filename to get the extension.

                  $filename_parts = explode( '.', $filename );

                  $extension = $filename_parts[1];

                   

                   

                  // Create an array of mime types that can be handled as images.

                  $image_mime_types = array( 'gif', 'jpeg', 'jpg', 'png' );

                   

                   

                  // If the file in the container can be treated as an image...

                  if ( in_array ( $extension, $image_mime_types ) ) {

                   

                   

                            // Get the binary data from the container.

                            $container_content = $fm -> getContainerData ( $record -> getField ( $field -> getName() ) );

                   

                   

                            // Display the image.

                            echo '<img src="data:image/' . $extension . ';base64,' . base64_encode ( $container_content ) . '" id="image-' . str_replace ( " ", "-", $field -> getName() ) . '" class="image-container">';

                   

                  } else {

                   

                        echo 'Mime type "' .  $extension . '" is not yet supported.';

                   

                  }

                  • 7. Re: Accessing data in a container field with external storage via php
                    FredBloggs

                    OK… I haven't needed this until now, when I decided to move certain containers to external storage. I really struggled to get it working with PHP and finally fell on this short sweet and efficient solution. Code, just how I like it @ !