| Version 2 (modified by forgacs, 20 months ago) |
|---|
Retrieve the upload progress
http://mediamosa.org/content/retrieve-upload-progress-1
If you want to use the uploadprogress, your system must have apc or uploadprogress extension. We suggest apc.
You can check your system about existence of apc here: http://your-mediamosa/admin/reports/status/php
http://pecl.php.net/package/apc
APC (Alternative PHP Cache is a PECL extension of PHP) should be installed on the server where the users upload their files.
Your page should contains the following:
/**
* Determine which upload progress implementation to use, if any available.
*/
function upload_progress_implementation() {
static $implementation;
if (!isset($implementation)) {
if (extension_loaded('apc') && ini_get('apc.rfc1867')) {
$implementation = 'apc';
}
else if (extension_loaded('uploadprogress')) {
$implementation = 'uploadprogress';
}
}
return $implementation;
}
... Your Drupal form should have:
// Uploadprogress field.
if ($implementation = upload_progress_implementation()) {
$upload_progress_key = md5(mt_rand());
if ($implementation == 'apc') {
$form['APC_UPLOAD_PROGRESS'] = array('#type' => 'hidden', '#value' => $upload_progress_key);
}
else if ($implementation == 'uploadprogress') {
$form['UPLOAD_IDENTIFIER'] = array('#type' => 'hidden', '#value' => $upload_progress_key);
}
}
The id (upload progress key) should be random. Don't use constant.
Then you can ask the /mediafile/uploadprogress [GET] REST call with id=$upload_progress_key .
If you don't want to use Drupal, this is the pure PHP / HTML version:
<input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key" value="<?php echo $upload_progress_key?>" />
http://pecl.php.net/bugs/bug.php?id=13583
According to the PECL ticket we should write the progress key before the file input. Eg.
<form action="http://upload.your-mediamosa/mediafile/upload?upload_ticket=xxx" enctype="multipart/form-data" method="POST"> <input id="progress_key" type="hidden" name="APC_UPLOAD_PROGRESS" value="2685770" /> <input class="FlesFileInput" type="file" value="" name="file" /> <input type="hidden" value="http://your-wle/test.html" name="redirect_uri" /> <input type="hidden" value="true" name="create_still" /> <input type="submit" /> </form>
