Labs (All)‎ > ‎

PHP Lab 1: Building an eCard System

In this exercise, you'll be developing a full-featured application to create digital greeting cards or eCards and store them in a simple database. Users of the application will be able to browse images on their file system to use with the greeting card and save it along with a simple greeting. The project can be divided into three main tasks/pages:
  • choose_image.php displays images from the local file system in a form. When the form is submitted, the selected image's location is passed on to the next page.
  • create_card.php displays the selected image and a form for entering a custom greeting and an email address for the intended recipient. When the form is submitted, the information is passed to the next page.
  • send_card.php processes the image location and greeting text passed to it and sends an email to the address provided.

Each of the files listed above is provided in the attached download named incomplete_code.zip. Some of the code is already written; in fact, you can run this skeleton project as is, although it won't do anything interesting until you complete the implementation. The sections below list the incomplete functions and how to write the code to achieve the end result described above. A full implementation (complete_code.zip) is attached as well so you can compare your end result with ours, but no peeking until the end!


Part A

In this section, you'll be completing image_select.php. You'll be exercising the concepts covered in PHP Basics by writing code to access the file system and retrieve a listing of all files in a directory. The code for presenting the images to the user is already complete.

Before you begin, look at the code that has already been written to get a feeling for how it works. The code currently consists of a set of functions (be sure to sneak another peek at the PHP Basics sheet if you need a refresher on how functions work in PHP) followed by a single invocation at the very bottom of the script, which executes the main function. main calls an as-yet-unimplemented function, fetch_images_from_file_system, which will do the file system accessing and return an array of image locations. Finally, the returned array is passed into a complete displayForm function which, as its name suggests, outputs an HTML-based form and the images from the file system to the screen. An images directory is included which you can use for your form.

This is the function you will have to implement. Right now, it just returns null:

function fetch_images_from_file_system()
{
return null;
}

You need to write the code, using the documentation provided in the PHP Basics sheet, to retrieve the list of files in the provided images directory. You can test if you have the right output by passing the array returned from the function into the print debug function print_r -- you should see the following:

Array
(
[0] => _images/3191747133_99f4d14198.jpg
[1] => _images/3191754369_5b793ede74.jpg
[2] => _images/3191775575_1c505c2841.jpg
[3] => _images/3192614850_ef3cb462e0.jpg
[4] => _images/3192621350_d205ddd721.jpg
)


Part B

In this section, you'll be working on create_card.php, which accepts a URL to an image via the query string and displays a form for users to enter a custom greeting and an email address to send the card to. For this part, you will use the special arrays discussed in the sheet to access the image passed in through the URL. The image is accessed directly in main and passed into display_form which actually builds and renders the form onscreen. Currently, main looks like:

function main()
{
$img = null;

// Display cration form
display_form($img);
}

You should change this so that when the following URL is submitted, you see the image below it displayed onscreen:

http://localhost/WebDevEDU/php/exercise1/complete_code/create_card.php?img=_images%2F3191747133_99f4d14198.jpg

Part C

In this section, you'll complete send_card.php. This script is responsible for saving the created card in the database and sending the email to the recipient specified in the previous script. You'll be completing the get_card_object function which currently returns a null object. You should create a new card instance (refer to the section on classes in the PHP Basics sheet) and set its properties accordingly given the parameters passed in to the script.

Č
ċ
ď
Jason Cooper,
Jan 21, 2009 2:21 AM
ċ
ď
Jason Cooper,
Jan 21, 2009 2:20 AM