Home
Username:
Password:
FileMaker 9 & PHP Foundations Tutorials

Working with Container Data / Exporting Container Data




Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com’s entire library of video tutorials.


Learn More

Subtitles of the Movie

In this lesson we're going to talk about the ability to take an image that we get from a container field and actually save it on the hard drive of the web server. You can tell the web server to save this container image file to the file directory. Why would we want to do that? Well, when you get pictures out of the database server, it's not near as fast as actually displaying pictures that are located on the local file directory. If you have a picture, let's say, that's used as your header inside of your website, you don't want to actually have to pull that header every time you go from page to page in your website. If you pull that header from the database every single time, you're going to get a performance hit that you don't want. What you could do is when you first load the page, you could grab that picture from the database and then save it on the hard drive of the web server. Then you can just use that picture throughout the rest of your other files. You can also store images for other reasons such as a customized login entry or customized personal files. Just the fact that you can take a container image out of the database and save it to the hard drive is a great plus. You don't have to use any plug ins. You can just use the API and a little PHP. Let's go ahead and show you how to do that. Inside of our 1402 project folder, let's open up the index.php file. Here we're going to use the same methods that we used down here to get our picture, but instead of passing that stream back to this image tag, we're actually going to store it on the hard drive. Up here we'll write some of that same code over. Well say that our path is equal to and then a random record get field and the field is going to be our picture field. Now what we want to do is go ahead and get that picture from the database server using our path. And this time we're just going to store it inside of a variable called picture. So picture is equal to the FileMaker object instance running the method get container data and passing the path. Now the stream has been stored inside the picture variable. So what we need to do is store this on a file somewhere inside of our directory. We need to create a file that is writeable by the web server. In other words, the web server has permission to write to that file. So we'll create a new folder and we'll call it picture. We'll put it in our 1402 project folder and we'll look at the privileges on that to make sure that the www group has write permissions. Now that the web server can write to it and everyone else can only read, we're ready to be able to store our picture in the picture folder. To do this, we first need to change the directory from our current script writing, which is index, into the picture directory. Now we just use a file put contents method to save our picture. We'll put write result is equal to file put contents and it takes two parameters. One's going to be the name of the file and we'll say that our file's going to be called picture.jif and we need to pass the actual picture to be stored in that file. So we'll pass our picture variable. Now, we're naming it picture.jif, even though we don't know if it's really going to be a jif picture. The reason why is because we want to give it an extension that, number one, the web browsers are going to be able to understand or, two, your operating system's going to understand. If you just give a generic JPEG or jif extension, then most likely your operating system or the browser's going to be able to work with it. So, now that we've stored it in there as the picture jif, let's go ahead then and point our image tag to that picture instead of the one that we are streaming from the database. So our image source now is going to be changed to the picture folder, picture.jif. Let's go ahead now and refresh our browser. Here we're seeing our picture, but this time instead of coming from the database, it's coming from inside our picture folder as picture.jif. Likewise, we could also change this so that we're actually going to store all the pictures that come out by appending in the name, or putting in the name our record ID to make sure that every file name is unique. Then we'll just need to make sure that we use this as our picture path. So our picture source is going to be equal to rec ID picture. And then down here we'll output that source. Now let's refresh this and let's watch our picture folder fill up with all our pictures. Oops, we're not getting our source correct here. Probably because we forgot to specify the folder. There we go. So we're able to take images out of our container fields and save them to the hard drive. We're doing this without any third-party utilities or plug-ins. One of the great things about using PHP is all the ways you can interact with your FileMaker database and extend its abilities by just learning how to program with the PHP language. This concludes our lesson on exporting container data.

Tutorial Information

Course: FileMaker 9 & PHP Foundations
Author: Lance Hallberg
SKU: 33786
ISBN: 1-933736-99-2
Release Date: 2007-08-22
Duration: 9.5 hrs / 107 lessons
Work Files: Yes
Captions: For Online University members only
Compatibility: Vista/XP/2000, OS X, Linux
QuickTime 7, Flash 8

VTC Sign up & Benefits

  • Unlimited Access
  • 98,729 Video Tutorials (23,265 free)
  • Video Available as Flash or QuickTime
  • Over 1026 Courses
  • $30 for One Month Access
  • Multi-User Discounts Available