diff options
Diffstat (limited to 'sites/all/libraries/plupload/examples')
8 files changed, 897 insertions, 0 deletions
diff --git a/sites/all/libraries/plupload/examples/custom.html b/sites/all/libraries/plupload/examples/custom.html new file mode 100644 index 000000000..3850ade27 --- /dev/null +++ b/sites/all/libraries/plupload/examples/custom.html @@ -0,0 +1,85 @@ +<!DOCTYPE html> +<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr"> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> + +<title>Plupload - Custom example</title> + +<!-- production --> +<script type="text/javascript" src="../js/plupload.full.min.js"></script> + + +<!-- debug +<script type="text/javascript" src="../js/moxie.js"></script> +<script type="text/javascript" src="../js/plupload.dev.js"></script> +--> + +</head> +<body style="font: 13px Verdana; background: #eee; color: #333"> + +<h1>Custom example</h1> + +<p>Shows you how to use the core plupload API.</p> + +<div id="filelist">Your browser doesn't have Flash, Silverlight or HTML5 support.</div> +<br /> + +<div id="container"> + <a id="pickfiles" href="javascript:;">[Select files]</a> + <a id="uploadfiles" href="javascript:;">[Upload files]</a> +</div> + +<br /> +<pre id="console"></pre> + + +<script type="text/javascript"> +// Custom example logic + +var uploader = new plupload.Uploader({ + runtimes : 'html5,flash,silverlight,html4', + browse_button : 'pickfiles', // you can pass an id... + container: document.getElementById('container'), // ... or DOM Element itself + url : 'upload.php', + flash_swf_url : '../js/Moxie.swf', + silverlight_xap_url : '../js/Moxie.xap', + + filters : { + max_file_size : '10mb', + mime_types: [ + {title : "Image files", extensions : "jpg,gif,png"}, + {title : "Zip files", extensions : "zip"} + ] + }, + + init: { + PostInit: function() { + document.getElementById('filelist').innerHTML = ''; + + document.getElementById('uploadfiles').onclick = function() { + uploader.start(); + return false; + }; + }, + + FilesAdded: function(up, files) { + plupload.each(files, function(file) { + document.getElementById('filelist').innerHTML += '<div id="' + file.id + '">' + file.name + ' (' + plupload.formatSize(file.size) + ') <b></b></div>'; + }); + }, + + UploadProgress: function(up, file) { + document.getElementById(file.id).getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>"; + }, + + Error: function(up, err) { + document.getElementById('console').appendChild(document.createTextNode("\nError #" + err.code + ": " + err.message)); + } + } +}); + +uploader.init(); + +</script> +</body> +</html> diff --git a/sites/all/libraries/plupload/examples/dump.php b/sites/all/libraries/plupload/examples/dump.php new file mode 100644 index 000000000..3ce4471f7 --- /dev/null +++ b/sites/all/libraries/plupload/examples/dump.php @@ -0,0 +1,27 @@ +<!DOCTYPE html> +<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr"> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> +<title>Plupload - Form dump</title> +</head> +<body style="font: 13px Verdana; background: #eee; color: #333"> + +<h1>Post dump</h1> + +<p>Shows the form items posted.</p> + +<table> + <tr> + <th>Name</th> + <th>Value</th> + </tr> + <?php $count = 0; foreach ($_POST as $name => $value) { ?> + <tr class="<?php echo $count % 2 == 0 ? 'alt' : ''; ?>"> + <td><?php echo htmlentities(stripslashes($name)) ?></td> + <td><?php echo nl2br(htmlentities(stripslashes($value))) ?></td> + </tr> + <?php } ?> +</table> + +</body> +</html> diff --git a/sites/all/libraries/plupload/examples/events.html b/sites/all/libraries/plupload/examples/events.html new file mode 100644 index 000000000..dd05e75d6 --- /dev/null +++ b/sites/all/libraries/plupload/examples/events.html @@ -0,0 +1,217 @@ +<!DOCTYPE html> +<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr"> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> + +<title>Plupload - Events example</title> + +<!-- production --> +<script type="text/javascript" src="../js/plupload.full.min.js"></script> + + +<!-- debug +<script type="text/javascript" src="../js/moxie.js"></script> +<script type="text/javascript" src="../js/plupload.dev.js"></script> +--> + +</head> +<body style="font: 13px Verdana; background: #eee; color: #333"> + +<h1>Events example</h1> + +<div id="container"> + <a id="pickfiles" href="javascript:;">[Select files]</a> + <a id="uploadfiles" href="javascript:;">[Upload files]</a> +</div> + +<br /> +<pre id="console"></pre> + +<script type="text/javascript"> + var uploader = new plupload.Uploader({ + // General settings + runtimes : 'silverlight,html4', + browse_button : 'pickfiles', // you can pass in id... + url : 'upload.php', + chunk_size : '1mb', + unique_names : true, + + // Resize images on client-side if we can + resize : { width : 320, height : 240, quality : 90 }, + + filters : { + max_file_size : '10mb', + + // Specify what files to browse for + mime_types: [ + {title : "Image files", extensions : "jpg,gif,png"}, + {title : "Zip files", extensions : "zip"} + ] + }, + + flash_swf_url : '../js/Moxie.swf', + silverlight_xap_url : '../js/Moxie.xap', + + // PreInit events, bound before the internal events + preinit : { + Init: function(up, info) { + log('[Init]', 'Info:', info, 'Features:', up.features); + }, + + UploadFile: function(up, file) { + log('[UploadFile]', file); + + // You can override settings before the file is uploaded + // up.setOption('url', 'upload.php?id=' + file.id); + // up.setOption('multipart_params', {param1 : 'value1', param2 : 'value2'}); + } + }, + + // Post init events, bound after the internal events + init : { + PostInit: function() { + // Called after initialization is finished and internal event handlers bound + log('[PostInit]'); + + document.getElementById('uploadfiles').onclick = function() { + uploader.start(); + return false; + }; + }, + + Browse: function(up) { + // Called when file picker is clicked + log('[Browse]'); + }, + + Refresh: function(up) { + // Called when the position or dimensions of the picker change + log('[Refresh]'); + }, + + StateChanged: function(up) { + // Called when the state of the queue is changed + log('[StateChanged]', up.state == plupload.STARTED ? "STARTED" : "STOPPED"); + }, + + QueueChanged: function(up) { + // Called when queue is changed by adding or removing files + log('[QueueChanged]'); + }, + + OptionChanged: function(up, name, value, oldValue) { + // Called when one of the configuration options is changed + log('[OptionChanged]', 'Option Name: ', name, 'Value: ', value, 'Old Value: ', oldValue); + }, + + BeforeUpload: function(up, file) { + // Called right before the upload for a given file starts, can be used to cancel it if required + log('[BeforeUpload]', 'File: ', file); + }, + + UploadProgress: function(up, file) { + // Called while file is being uploaded + log('[UploadProgress]', 'File:', file, "Total:", up.total); + }, + + FileFiltered: function(up, file) { + // Called when file successfully files all the filters + log('[FileFiltered]', 'File:', file); + }, + + FilesAdded: function(up, files) { + // Called when files are added to queue + log('[FilesAdded]'); + + plupload.each(files, function(file) { + log(' File:', file); + }); + }, + + FilesRemoved: function(up, files) { + // Called when files are removed from queue + log('[FilesRemoved]'); + + plupload.each(files, function(file) { + log(' File:', file); + }); + }, + + FileUploaded: function(up, file, info) { + // Called when file has finished uploading + log('[FileUploaded] File:', file, "Info:", info); + }, + + ChunkUploaded: function(up, file, info) { + // Called when file chunk has finished uploading + log('[ChunkUploaded] File:', file, "Info:", info); + }, + + UploadComplete: function(up, files) { + // Called when all files are either uploaded or failed + log('[UploadComplete]'); + }, + + Destroy: function(up) { + // Called when uploader is destroyed + log('[Destroy] '); + }, + + Error: function(up, args) { + // Called when error occurs + log('[Error] ', args); + } + } + }); + + + function log() { + var str = ""; + + plupload.each(arguments, function(arg) { + var row = ""; + + if (typeof(arg) != "string") { + plupload.each(arg, function(value, key) { + // Convert items in File objects to human readable form + if (arg instanceof plupload.File) { + // Convert status to human readable + switch (value) { + case plupload.QUEUED: + value = 'QUEUED'; + break; + + case plupload.UPLOADING: + value = 'UPLOADING'; + break; + + case plupload.FAILED: + value = 'FAILED'; + break; + + case plupload.DONE: + value = 'DONE'; + break; + } + } + + if (typeof(value) != "function") { + row += (row ? ', ' : '') + key + '=' + value; + } + }); + + str += row + " "; + } else { + str += arg + " "; + } + }); + + var log = document.getElementById('console'); + log.innerHTML += str + "\n"; + } + + uploader.init(); + +</script> +</body> +</html>
\ No newline at end of file diff --git a/sites/all/libraries/plupload/examples/jquery/all_runtimes.html b/sites/all/libraries/plupload/examples/jquery/all_runtimes.html new file mode 100644 index 000000000..ea44a9ba6 --- /dev/null +++ b/sites/all/libraries/plupload/examples/jquery/all_runtimes.html @@ -0,0 +1,139 @@ +<!DOCTYPE html> +<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr"> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> + +<title>Plupload - Queue widget example</title> + +<link rel="stylesheet" href="../../js/jquery.plupload.queue/css/jquery.plupload.queue.css" type="text/css" media="screen" /> + +<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> + +<!-- production --> +<script type="text/javascript" src="../../js/plupload.full.min.js"></script> +<script type="text/javascript" src="../../js/jquery.plupload.queue/jquery.plupload.queue.js"></script> + +<!-- debug +<script type="text/javascript" src="../../js/moxie.js"></script> +<script type="text/javascript" src="../../js/plupload.dev.js"></script> +<script type="text/javascript" src="../../js/jquery.plupload.queue/jquery.plupload.queue.js"></script> +--> + +</head> +<body style="font: 13px Verdana; background: #eee; color: #333"> + +<form method="post" action="dump.php"> + <h1>Queue widget example</h1> + + <p>Shows the jQuery Plupload Queue widget and under different runtimes.</p> + + <div style="float: left; margin-right: 20px"> + <h3>Flash runtime</h3> + <div id="flash_uploader" style="width: 500px; height: 330px;">Your browser doesn't have Flash installed.</div> + + <h3>Silverlight runtime</h3> + <div id="silverlight_uploader" style="width: 500px; height: 330px;">Your browser doesn't have Silverlight installed.</div> + </div> + + <div style="float: left; margin-right: 20px"> + <h3>HTML 4 runtime</h3> + <div id="html4_uploader" style="width: 500px; height: 330px;">Your browser doesn't have HTML 4 support.</div> + + <h3>HTML 5 runtime</h3> + <div id="html5_uploader" style="width: 500px; height: 330px;">Your browser doesn't support native upload.</div> + </div> + + <br style="clear: both" /> + + <input type="submit" value="Send" /> +</form> + +<script type="text/javascript"> +$(function() { + // Setup flash version + $("#flash_uploader").pluploadQueue({ + // General settings + runtimes : 'flash', + url : '../upload.php', + chunk_size : '1mb', + unique_names : true, + + filters : { + max_file_size : '10mb', + mime_types: [ + {title : "Image files", extensions : "jpg,gif,png"}, + {title : "Zip files", extensions : "zip"} + ] + }, + + // Resize images on clientside if we can + resize : {width : 320, height : 240, quality : 90}, + + // Flash settings + flash_swf_url : '../../js/Moxie.swf' + }); + + + // Setup silverlight version + $("#silverlight_uploader").pluploadQueue({ + // General settings + runtimes : 'silverlight', + url : '../upload.php', + chunk_size : '1mb', + unique_names : true, + + filters : { + max_file_size : '10mb', + mime_types: [ + {title : "Image files", extensions : "jpg,gif,png"}, + {title : "Zip files", extensions : "zip"} + ] + }, + + // Resize images on clientside if we can + resize : {width : 320, height : 240, quality : 90}, + + // Silverlight settings + silverlight_xap_url : '../../js/Moxie.xap' + }); + + // Setup html5 version + $("#html5_uploader").pluploadQueue({ + // General settings + runtimes : 'html5', + url : '../upload.php', + chunk_size : '1mb', + unique_names : true, + + filters : { + max_file_size : '10mb', + mime_types: [ + {title : "Image files", extensions : "jpg,gif,png"}, + {title : "Zip files", extensions : "zip"} + ] + }, + + // Resize images on clientside if we can + resize : {width : 320, height : 240, quality : 90} + }); + + + // Setup html4 version + $("#html4_uploader").pluploadQueue({ + // General settings + runtimes : 'html4', + url : '../upload.php', + unique_names : true, + + filters : { + mime_types: [ + {title : "Image files", extensions : "jpg,gif,png"}, + {title : "Zip files", extensions : "zip"} + ] + } + }); +}); +</script> + +</body> +</html> diff --git a/sites/all/libraries/plupload/examples/jquery/jquery_ui_widget.html b/sites/all/libraries/plupload/examples/jquery/jquery_ui_widget.html new file mode 100644 index 000000000..1beb6c152 --- /dev/null +++ b/sites/all/libraries/plupload/examples/jquery/jquery_ui_widget.html @@ -0,0 +1,113 @@ +<!DOCTYPE html> +<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr"> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> + +<title>Plupload - jQuery UI Widget</title> + +<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/base/jquery-ui.css" type="text/css" /> +<link rel="stylesheet" href="../../js/jquery.ui.plupload/css/jquery.ui.plupload.css" type="text/css" /> + +<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> +<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script> + +<!-- production --> +<script type="text/javascript" src="../../js/plupload.full.min.js"></script> +<script type="text/javascript" src="../../js/jquery.ui.plupload/jquery.ui.plupload.js"></script> + +<!-- debug +<script type="text/javascript" src="../../js/moxie.js"></script> +<script type="text/javascript" src="../../js/plupload.dev.js"></script> +<script type="text/javascript" src="../../js/jquery.ui.plupload/jquery.ui.plupload.js"></script> +--> + +</head> +<body style="font: 13px Verdana; background: #eee; color: #333"> + +<h1>jQuery UI Widget</h1> + +<p>You can see this example with different themes on the <a href="http://plupload.com/example_jquery_ui.php">www.plupload.com</a> website.</p> + +<form id="form" method="post" action="../dump.php"> + <div id="uploader"> + <p>Your browser doesn't have Flash, Silverlight or HTML5 support.</p> + </div> + <br /> + <input type="submit" value="Submit" /> +</form> + +<script type="text/javascript"> +// Initialize the widget when the DOM is ready +$(function() { + $("#uploader").plupload({ + // General settings + runtimes : 'html5,flash,silverlight,html4', + url : '../upload.php', + + // User can upload no more then 20 files in one go (sets multiple_queues to false) + max_file_count: 20, + + chunk_size: '1mb', + + // Resize images on clientside if we can + resize : { + width : 200, + height : 200, + quality : 90, + crop: true // crop to exact dimensions + }, + + filters : { + // Maximum file size + max_file_size : '1000mb', + // Specify what files to browse for + mime_types: [ + {title : "Image files", extensions : "jpg,gif,png"}, + {title : "Zip files", extensions : "zip"} + ] + }, + + // Rename files by clicking on their titles + rename: true, + + // Sort files + sortable: true, + + // Enable ability to drag'n'drop files onto the widget (currently only HTML5 supports that) + dragdrop: true, + + // Views to activate + views: { + list: true, + thumbs: true, // Show thumbs + active: 'thumbs' + }, + + // Flash settings + flash_swf_url : '../../js/Moxie.swf', + + // Silverlight settings + silverlight_xap_url : '../../js/Moxie.xap' + }); + + + // Handle the case when form was submitted before uploading has finished + $('#form').submit(function(e) { + // Files in queue upload them first + if ($('#uploader').plupload('getFiles').length > 0) { + + // When all files are uploaded submit form + $('#uploader').on('complete', function() { + $('#form')[0].submit(); + }); + + $('#uploader').plupload('start'); + } else { + alert("You must have at least one file in the queue."); + } + return false; // Keep the form from submitting + }); +}); +</script> +</body> +</html> diff --git a/sites/all/libraries/plupload/examples/jquery/queue_widget.html b/sites/all/libraries/plupload/examples/jquery/queue_widget.html new file mode 100644 index 000000000..485528706 --- /dev/null +++ b/sites/all/libraries/plupload/examples/jquery/queue_widget.html @@ -0,0 +1,66 @@ +<!DOCTYPE html> +<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr"> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> + +<title>Plupload - Queue widget example</title> + +<link rel="stylesheet" href="../../js/jquery.plupload.queue/css/jquery.plupload.queue.css" type="text/css" media="screen" /> + +<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> + +<!-- production --> +<script type="text/javascript" src="../../js/plupload.full.min.js"></script> +<script type="text/javascript" src="../../js/jquery.plupload.queue/jquery.plupload.queue.js"></script> + +<!-- debug +<script type="text/javascript" src="../../js/moxie.js"></script> +<script type="text/javascript" src="../../js/plupload.dev.js"></script> +<script type="text/javascript" src="../../js/jquery.plupload.queue/jquery.plupload.queue.js"></script> +--> + + +</head> +<body style="font: 13px Verdana; background: #eee; color: #333"> + +<form method="post" action="dump.php"> + <div id="uploader"> + <p>Your browser doesn't have Flash, Silverlight or HTML5 support.</p> + </div> + <input type="submit" value="Send" /> +</form> + +<script type="text/javascript"> +$(function() { + + // Setup html5 version + $("#uploader").pluploadQueue({ + // General settings + runtimes : 'html5,flash,silverlight,html4', + url : '../upload.php', + chunk_size: '1mb', + rename : true, + dragdrop: true, + + filters : { + // Maximum file size + max_file_size : '10mb', + // Specify what files to browse for + mime_types: [ + {title : "Image files", extensions : "jpg,gif,png"}, + {title : "Zip files", extensions : "zip"} + ] + }, + + // Resize images on clientside if we can + resize : {width : 320, height : 240, quality : 90}, + + flash_swf_url : '../../js/Moxie.swf', + silverlight_xap_url : '../../js/Moxie.xap' + }); + +}); +</script> + +</body> +</html> diff --git a/sites/all/libraries/plupload/examples/jquery/s3.php b/sites/all/libraries/plupload/examples/jquery/s3.php new file mode 100644 index 000000000..a46f1dbc6 --- /dev/null +++ b/sites/all/libraries/plupload/examples/jquery/s3.php @@ -0,0 +1,125 @@ +<?php +/* +In order to upload files to S3 using Flash runtime, one should start by placing crossdomain.xml into the bucket. +crossdomain.xml can be as simple as this: + +<?xml version="1.0"?> +<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"> +<cross-domain-policy> +<allow-access-from domain="*" secure="false" /> +</cross-domain-policy> + +In our tests SilverLight didn't require anything special and worked with this configuration just fine. It may fail back +to the same crossdomain.xml as last resort. + +!!!Important!!! Plupload UI Widget here, is used only for demo purposes and is not required for uploading to S3. +*/ + +// important variables that will be used throughout this example +$bucket = 'BUCKET'; + +// these can be found on your Account page, under Security Credentials > Access Keys +$accessKeyId = 'ACCESS_KEY_ID'; +$secret = 'SECRET_ACCESS_KEY'; + +// prepare policy +$policy = base64_encode(json_encode(array( + // ISO 8601 - date('c'); generates uncompatible date, so better do it manually + 'expiration' => date('Y-m-d\TH:i:s.000\Z', strtotime('+1 day')), + 'conditions' => array( + array('bucket' => $bucket), + array('acl' => 'public-read'), + array('starts-with', '$key', ''), + // for demo purposes we are accepting only images + array('starts-with', '$Content-Type', 'image/'), + // Plupload internally adds name field, so we need to mention it here + array('starts-with', '$name', ''), + // One more field to take into account: Filename - gets silently sent by FileReference.upload() in Flash + // http://docs.amazonwebservices.com/AmazonS3/latest/dev/HTTPPOSTFlash.html + array('starts-with', '$Filename', ''), + ) +))); + +// sign policy +$signature = base64_encode(hash_hmac('sha1', $policy, $secret, true)); + +?> +<!DOCTYPE html> +<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr"> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> + +<title>Plupload to Amazon S3 Example</title> + +<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/base/jquery-ui.css" type="text/css" /> +<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> +<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script> + +<!-- Load plupload and all it's runtimes and finally the UI widget --> +<link rel="stylesheet" href="../../js/jquery.ui.plupload/css/jquery.ui.plupload.css" type="text/css" /> + + +<!-- production --> +<script type="text/javascript" src="../../js/plupload.full.min.js"></script> +<script type="text/javascript" src="../../js/jquery.ui.plupload/jquery.ui.plupload.js"></script> + +<!-- debug +<script type="text/javascript" src="../../js/moxie.js"></script> +<script type="text/javascript" src="../../js/plupload.dev.js"></script> +<script type="text/javascript" src="../../js/jquery.ui.plupload/jquery.ui.plupload.js"></script> +--> + +</head> +<body style="font: 13px Verdana; background: #eee; color: #333"> + +<h1>Plupload to Amazon S3 Example</h1> + +<div id="uploader"> + <p>Your browser doesn't have Flash, Silverlight or HTML5 support.</p> +</div> + +<script type="text/javascript"> +// Convert divs to queue widgets when the DOM is ready +$(function() { + $("#uploader").plupload({ + runtimes : 'html5,flash,silverlight', + url : 'http://<?php echo $bucket; ?>.s3.amazonaws.com/', + + multipart: true, + multipart_params: { + 'key': '${filename}', // use filename as a key + 'Filename': '${filename}', // adding this to keep consistency across the runtimes + 'acl': 'public-read', + 'Content-Type': 'image/jpeg', + 'AWSAccessKeyId' : '<?php echo $accessKeyId; ?>', + 'policy': '<?php echo $policy; ?>', + 'signature': '<?php echo $signature; ?>' + }, + + // !!!Important!!! + // this is not recommended with S3, since it will force Flash runtime into the mode, with no progress indication + //resize : {width : 800, height : 600, quality : 60}, // Resize images on clientside, if possible + + // optional, but better be specified directly + file_data_name: 'file', + + filters : { + // Maximum file size + max_file_size : '10mb', + // Specify what files to browse for + mime_types: [ + {title : "Image files", extensions : "jpg,jpeg"} + ] + }, + + // Flash settings + flash_swf_url : '../../js/Moxie.swf', + + // Silverlight settings + silverlight_xap_url : '../../js/Moxie.xap' + }); +}); +</script> + +</body> +</html> diff --git a/sites/all/libraries/plupload/examples/upload.php b/sites/all/libraries/plupload/examples/upload.php new file mode 100644 index 000000000..0b7276ce7 --- /dev/null +++ b/sites/all/libraries/plupload/examples/upload.php @@ -0,0 +1,125 @@ +<?php +/** + * upload.php + * + * Copyright 2013, Moxiecode Systems AB + * Released under GPL License. + * + * License: http://www.plupload.com/license + * Contributing: http://www.plupload.com/contributing + */ + +#!! IMPORTANT: +#!! this file is just an example, it doesn't incorporate any security checks and +#!! is not recommended to be used in production environment as it is. Be sure to +#!! revise it and customize to your needs. + + +// Make sure file is not cached (as it happens for example on iOS devices) +header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); +header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); +header("Cache-Control: no-store, no-cache, must-revalidate"); +header("Cache-Control: post-check=0, pre-check=0", false); +header("Pragma: no-cache"); + +/* +// Support CORS +header("Access-Control-Allow-Origin: *"); +// other CORS headers if any... +if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') { + exit; // finish preflight CORS requests here +} +*/ + +// 5 minutes execution time +@set_time_limit(5 * 60); + +// Uncomment this one to fake upload time +// usleep(5000); + +// Settings +$targetDir = ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . "plupload"; +//$targetDir = 'uploads'; +$cleanupTargetDir = true; // Remove old files +$maxFileAge = 5 * 3600; // Temp file age in seconds + + +// Create target dir +if (!file_exists($targetDir)) { + @mkdir($targetDir); +} + +// Get a file name +if (isset($_REQUEST["name"])) { + $fileName = $_REQUEST["name"]; +} elseif (!empty($_FILES)) { + $fileName = $_FILES["file"]["name"]; +} else { + $fileName = uniqid("file_"); +} + +$filePath = $targetDir . DIRECTORY_SEPARATOR . $fileName; + +// Chunking might be enabled +$chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0; +$chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 0; + + +// Remove old temp files +if ($cleanupTargetDir) { + if (!is_dir($targetDir) || !$dir = opendir($targetDir)) { + die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}'); + } + + while (($file = readdir($dir)) !== false) { + $tmpfilePath = $targetDir . DIRECTORY_SEPARATOR . $file; + + // If temp file is current file proceed to the next + if ($tmpfilePath == "{$filePath}.part") { + continue; + } + + // Remove temp file if it is older than the max age and is not the current file + if (preg_match('/\.part$/', $file) && (filemtime($tmpfilePath) < time() - $maxFileAge)) { + @unlink($tmpfilePath); + } + } + closedir($dir); +} + + +// Open temp file +if (!$out = @fopen("{$filePath}.part", $chunks ? "ab" : "wb")) { + die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}'); +} + +if (!empty($_FILES)) { + if ($_FILES["file"]["error"] || !is_uploaded_file($_FILES["file"]["tmp_name"])) { + die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}'); + } + + // Read binary input stream and append it to temp file + if (!$in = @fopen($_FILES["file"]["tmp_name"], "rb")) { + die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}'); + } +} else { + if (!$in = @fopen("php://input", "rb")) { + die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}'); + } +} + +while ($buff = fread($in, 4096)) { + fwrite($out, $buff); +} + +@fclose($out); +@fclose($in); + +// Check if file has been uploaded +if (!$chunks || $chunk == $chunks - 1) { + // Strip the temp .part suffix off + rename("{$filePath}.part", $filePath); +} + +// Return Success JSON-RPC response +die('{"jsonrpc" : "2.0", "result" : null, "id" : "id"}'); |