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