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

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

More information
Related Books
Learning PHP, MySQL, and JavaScript: A Step-By-Step Guide to Creating Dynamic Websites (Animal Guide)

Learning PHP, MySQL, and JavaScript: A Step-By-Step Guide to Creating Dynamic Websites (Animal Guide)

If you know HTML, this guide will have you building interactive websites quickly. You'll learn...

The Essential Guide to Dreamweaver CS4 with CSS, Ajax, and PHP (Essentials)

The Essential Guide to Dreamweaver CS4 with CSS, Ajax, and PHP (Essentials)

Dreamweaver CS4 is a massive step forward in terms of integration with the rest of the CS4 suite...
PhpRiot Newsletter
Your Email Address:

More information

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