PhpRiot
Download This Article
Download this article in PDF format with all listings and files.

Price: $5.00 AUD
(Approx. $4.45 USD)

More information
Related Books
The Essential Guide to Dreamweaver CS3 with CSS, Ajax, and PHP

The Essential Guide to Dreamweaver CS3 with CSS, Ajax, and PHP

With over 3 million users worldwide, Adobe's Dreamweaver is the most popular web development...

AJAX and PHP: Building Responsive Web Applications

AJAX and PHP: Building Responsive Web Applications

Building Responsive Web Applications with AJAX and PHP is the most practical and efficient...
Browse Articles
Ajax (4), APC (1), CAPTCHA (1), CSS (3), Debugging (1), File Upload (1), Google (3), Google Maps (2), JavaScript (11), JSON (2), MVC (1), MySQL (6), onbeforeunload (1), OOP (1), PHP (27), PhpDoc (1), PostgreSQL (6), Prototype (10), Reflection (1), RFC 1867 (1), Robots (1), Scriptaculous (1), SEO (1), Sessions (1), SimpleXML (1), Smarty (5), SOAP (1), SPL (1), Templates (2), W3C (1), XHTML (1), Zend Framework (1), Zend_Search_Lucene (1)

PhpRiot Newsletter
Your Email Address:

Monitoring File Uploads using Ajax and PHP

Retrieving a File's Upload Status

Next we write another PHP script, which is used to send back the status of a file as it is being uploaded. Essentially this is an interface to the getUploadStatus() method of the FileUploader PHP class.

This script will be utilized by the Ajax code we will develop later in this chapter.

As we saw earlier in this article, the getUploadStatus() method returns an array containing the upload data for the file with the given ID. We are going to send this data back to the browser using JSON (JavaScript Object Notation).

Since PHP 5.2.0, data can easily be encoded into JSON format using the json_encode() method. The HTTP Content-type header associated with JSON data is application/json.

Listing 13 Sending the status of a file as it is being uploaded (status.php)
<?php
    require_once('FileUploader.php');
 
    $id = isset($_POST['id']) ? $_POST['id'] : 0;
    $fu = new FileUploader();
 
    $status = $fu->getUploadStatus($id);
 
    header('Content-type: application/json');
    echo json_encode($status);
?>

In This Article


Additional Files