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

Handling the File Upload

In the index.php file created in the previous section, the form is submitted to a file called upload.php. The upload.php file is simply used to make a call to the upload() method of the FileUploader PHP class.

The other thing we do in this file is specify the directory where the file should be saved. Typically your own upload functionality will behave slightly different, but for our purposes this will suffice.

Note: This directory must be writable by the web server.
Listing 12 Handling the file upload (upload.php)
<?php
    require_once('FileUploader.php');
 
    $path = realpath(dirname(__FILE__) . '/uploads');
 
    $fu = new FileUploader();
    $fu->upload('myFile', $path);
?>

The first argument passed to upload() is the name of the file form element in index.php, while the second argument is the path where the file should be saved.

In This Article


Additional Files