// Set plain text headers header("Content-type: text/plain; charset=utf-8"); // Include the SDK require_once '../sdk.class.php'; // Include PEAR Console_ProgressBar require_once 'lib/ProgressBar.php'; /*%******************************************************************************************%*/ // DOWNLOAD SAMPLE FILE FROM S3 // Instantiate the AmazonS3 class $s3 = new AmazonS3(); // Instantiate a new progress bar. // We won't know the max number of bytes until the download starts, so we'll handle that in our callback. $progress_bar = new Console_ProgressBar('* %fraction% KB [%bar%] %percent%', '=>', ' ', 100, 1); $progress_bar->UPDATED = false; // Register a callback function to execute when a stream is written locally. $s3->register_streaming_write_callback('write_callback'); function write_callback($curl_handle, $length) { // Import from global scope $progress_bar = $GLOBALS['progress_bar']; // Have we updated the format with updated information yet? if (!$progress_bar->UPDATED) { // Add the Content-Length of the file as the max number of bytes. $progress_bar->reset('* %fraction% KB [%bar%] %percent%', '=>', ' ', 100, curl_getinfo($curl_handle, CURLINFO_CONTENT_LENGTH_DOWNLOAD)); $progress_bar->UPDATED = true; } // Update the progress bar with the cumulative number of bytes downloaded. $progress_bar->update(curl_getinfo($curl_handle, CURLINFO_SIZE_DOWNLOAD)); } // Add some spacing above the progress bar. echo PHP_EOL;