PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Monitoring File Uploads using Ajax and PHP

Introduction

Because of the limitations of HTTP, it is difficult to monitor the status of files as they are uploaded via HTML forms. While other programming languages have built-in methods to monitor file uploads, PHP does not. This article shows how to implement such a solution in PHP.

In order to achieve this, the APC (Alternative PHP Cache) PHP extension is required, as well as PHP 5. Specifically, APC 3.0.13 or newer and PHP 5.2 or newer are required for the code in this article to work. We will cover installation of APC in the next section. It is assumed you already have a working PHP 5.2 installation.

In this article we will develop a solution that will allow users to upload a file from their computer using HTML forms. We will then determine the progress of the upload while it is in progress using Ajax, and display the status to the user.

In addition to using PHP, we will also be using the Prototype JavaScript library (version 1.6.0), which you can download for free from http://www.prototypejs.org.

The steps we will follow in this article are as follows:

  • Installation of the APC extension for PHP.
  • How to monitor uploads using APC.
  • Creating a PHP class to manage file uploads.
  • Implementing a traditional file uploader.
  • Extending the uploader to display upload status.

In This Article


Additional Files