Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Learning PHP, Part 2: Upload files and use XML or JSON to store and display file information

Nicholas Chase is the founder and creator of NoTooMi. In addition to technical writing for large corporations, he has been involved in website development for companies such as Lucent Technologies, Sun Microsystems, Oracle, and the Tampa Bay Buccaneers. He has been a high school physics teacher, a low-level-radioactive waste facility manager, an online science fiction magazine editor, a multimedia engineer, an Oracle instructor, and the chief technology officer of an interactive communications company. He is the author of several books, including XML Primer Plus (Sams 2002).

Summary:  This tutorial is Part 2 of a three-part "Learning PHP" series teaching you how to use PHP through building a simple workflow application. Take this tutorial if you have a basic understanding of PHP and want to learn about uploading files from the browser, sessions, or using PHP to process XML or JSON.

03 Jan 2013 - Nicholas Chase updated content throughout this tutorial to reflect current PHP, XML, and JSON technology.

View more content in this series

Date:  03 Jan 2013 (Published 21 Jun 2005)
Level:  Intermediate PDF:  A4 and Letter (709 KB | 34 pages)Get Adobe® Reader®

Activity:  47606 views
Comments:  

Before you start

In this tutorial you will learn how to use sessions with PHP, how to manipulate XML data with the DOM, and how to create, use, and read JSON data in PHP.

About this tutorial

This tutorial teaches you how to use PHP by demonstrating the construction of a web-based workflow application. "Learning PHP, Part 1" covered the basics, such as syntax, functions, working with HTML forms submissions and databases, and creating a process by which a new user can register for an account.

In this tutorial, you will enable users to upload files to the system by using their browsers, and you will use first XML, then JSON to store and display information about each file.

Part 3 looks at using HTTP authentication, as well as protecting files by streaming them from a non-web-accessible directory. You'll also look at creating objects and using exceptions.

In the course of this tutorial, you'll examine:

  • Creating and using sessions and session information.
  • Uploading files from the browser.
  • Creating XML using the Document Object Model (DOM).
  • Manipulating XML data using DOM.
  • Creating JavaScript Object Notation (JSON) data.
  • Reading and using JSON data.

Who should take this tutorial?

This tutorial is Part 2 in a three-part series designed to teach you various aspects of working with PHP as you build a workflow application. Take this tutorial if you have a basic understanding of PHP and want to learn about uploading files from the browser, sessions, or using PHP to process XML or JSON.

This tutorial assumes a basic familiarity with PHP to the level discussed in Part 1 of this series. That includes basic understanding of control structures, such as loops and if-then statements, as well as functions and working with HTML form submissions and databases. Familiarity with XML is helpful, but not required. (You can find more information about these topics in Resources.)


Prerequisites

You need to have a web server, PHP, and a database installed and available. If you have a hosting account, you can use it as long as the server has PHP V5 installed and has access to a MySQL database. Otherwise, download and install the following packages:

XAMPP
Whether you're on Windows®, Linux®, or even Mac, the easiest way to get all of the necessary pieces of software for this tutorial is to install XAMPP, which includes a web server, PHP, and the MySQL database engine. If you choose to go this route, install and then run the control panel to start up the Apache and MySQL processes. You also have the option of installing the various pieces separately. Keep in mind that you then have to configure them to work together—a step already completed with XAMPP.
Web server
If you choose not to use XAMPP, you have several options for a web server. If you use PHP 5.4 (as of this writing, XAMPP is only using PHP 5.3.8) you can use the built-in web server for testing. For production, however, I assume that you're using the Apache Web server, version 2.x.
PHP 5.x
If you do not use XAMPP, you need to download PHP 5.x separately. The standard distribution includes everything you need for this tutorial. Feel free to download the binaries; you do not need the source for this tutorial (or ever, unless you want to hack on PHP itself). This tutorial was written and tested on PHP 5.3.8.
MySQL
Part of this project involves saving data to a database, so you need a database as well. Again, if you install XAMPP, you can skip this step, but if you choose to, you can install a database separately. In this tutorial, I concentrate on MySQL because it's commonly used with PHP. If you choose to go this route, you can download and install the Community Server.

1 of 10 | Next

Comments



static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Open source, Linux, XML
ArticleID=133660
TutorialTitle=Learning PHP, Part 2: Upload files and use XML or JSON to store and display file information
publish-date=01032013
author1-email=ibmquestions@nicholaschase.com
author1-email-cc=