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)
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.




