plupload-rails3 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE +38 -0
  4. data/README.md +100 -0
  5. data/Rakefile +23 -0
  6. data/init.rb +3 -0
  7. data/install.rb +9 -0
  8. data/lib/.DS_Store +0 -0
  9. data/lib/app/.DS_Store +0 -0
  10. data/lib/app/controllers/plupload_rails_controller.rb +38 -0
  11. data/lib/app/helpers/plupload_helper.rb +14 -0
  12. data/lib/app/middleware/plupload_params_renamer.rb +38 -0
  13. data/lib/app/views/.DS_Store +0 -0
  14. data/lib/app/views/plupload/_uploader_scripts.html.erb +72 -0
  15. data/lib/plupload-rails3.rb +20 -0
  16. data/lib/plupload-rails3/asset_mover.rb +54 -0
  17. data/lib/plupload-rails3/railtie.rb +12 -0
  18. data/lib/plupload-rails3/version.rb +5 -0
  19. data/lib/public/.DS_Store +0 -0
  20. data/lib/public/images/.DS_Store +0 -0
  21. data/lib/public/images/plupload-rails3/.DS_Store +0 -0
  22. data/lib/public/images/plupload-rails3/plupload/backgrounds.gif +0 -0
  23. data/lib/public/images/plupload-rails3/plupload/buttons-disabled.png +0 -0
  24. data/lib/public/images/plupload-rails3/plupload/buttons.png +0 -0
  25. data/lib/public/images/plupload-rails3/plupload/delete.gif +0 -0
  26. data/lib/public/images/plupload-rails3/plupload/done.gif +0 -0
  27. data/lib/public/images/plupload-rails3/plupload/error.gif +0 -0
  28. data/lib/public/images/plupload-rails3/plupload/transp50.png +0 -0
  29. data/lib/public/javascripts/.DS_Store +0 -0
  30. data/lib/public/javascripts/plupload-rails3/.DS_Store +0 -0
  31. data/lib/public/javascripts/plupload-rails3/jquery-ui.min.js +406 -0
  32. data/lib/public/javascripts/plupload-rails3/jquery.min.js +16 -0
  33. data/lib/public/javascripts/plupload-rails3/plupload/.DS_Store +0 -0
  34. data/lib/public/javascripts/plupload-rails3/plupload/changelog.txt +152 -0
  35. data/lib/public/javascripts/plupload-rails3/plupload/examples/.DS_Store +0 -0
  36. data/lib/public/javascripts/plupload-rails3/plupload/examples/bg.jpg +0 -0
  37. data/lib/public/javascripts/plupload-rails3/plupload/examples/custom.html +94 -0
  38. data/lib/public/javascripts/plupload-rails3/plupload/examples/dump.php +36 -0
  39. data/lib/public/javascripts/plupload-rails3/plupload/examples/jquery/events.html +196 -0
  40. data/lib/public/javascripts/plupload-rails3/plupload/examples/jquery/jquery_ui_widget.html +103 -0
  41. data/lib/public/javascripts/plupload-rails3/plupload/examples/jquery/queue_widget.html +174 -0
  42. data/lib/public/javascripts/plupload-rails3/plupload/examples/jquery/s3.php +158 -0
  43. data/lib/public/javascripts/plupload-rails3/plupload/examples/upload.php +124 -0
  44. data/lib/public/javascripts/plupload-rails3/plupload/js/.DS_Store +0 -0
  45. data/lib/public/javascripts/plupload-rails3/plupload/js/jquery.plupload.queue/.DS_Store +0 -0
  46. data/lib/public/javascripts/plupload-rails3/plupload/js/jquery.plupload.queue/css/jquery.plupload.queue.css +177 -0
  47. data/lib/public/javascripts/plupload-rails3/plupload/js/jquery.plupload.queue/img/backgrounds.gif +0 -0
  48. data/lib/public/javascripts/plupload-rails3/plupload/js/jquery.plupload.queue/img/buttons-disabled.png +0 -0
  49. data/lib/public/javascripts/plupload-rails3/plupload/js/jquery.plupload.queue/img/buttons.png +0 -0
  50. data/lib/public/javascripts/plupload-rails3/plupload/js/jquery.plupload.queue/img/delete.gif +0 -0
  51. data/lib/public/javascripts/plupload-rails3/plupload/js/jquery.plupload.queue/img/done.gif +0 -0
  52. data/lib/public/javascripts/plupload-rails3/plupload/js/jquery.plupload.queue/img/error.gif +0 -0
  53. data/lib/public/javascripts/plupload-rails3/plupload/js/jquery.plupload.queue/img/throbber.gif +0 -0
  54. data/lib/public/javascripts/plupload-rails3/plupload/js/jquery.plupload.queue/img/transp50.png +0 -0
  55. data/lib/public/javascripts/plupload-rails3/plupload/js/jquery.plupload.queue/jquery.plupload.queue.js +1 -0
  56. data/lib/public/javascripts/plupload-rails3/plupload/js/jquery.ui.plupload/.DS_Store +0 -0
  57. data/lib/public/javascripts/plupload-rails3/plupload/js/jquery.ui.plupload/css/jquery.ui.plupload.css +139 -0
  58. data/lib/public/javascripts/plupload-rails3/plupload/js/jquery.ui.plupload/img/plupload-bw.png +0 -0
  59. data/lib/public/javascripts/plupload-rails3/plupload/js/jquery.ui.plupload/img/plupload.png +0 -0
  60. data/lib/public/javascripts/plupload-rails3/plupload/js/jquery.ui.plupload/jquery.ui.plupload.js +1 -0
  61. data/lib/public/javascripts/plupload-rails3/plupload/js/plupload.browserplus.js +1 -0
  62. data/lib/public/javascripts/plupload-rails3/plupload/js/plupload.flash.js +1 -0
  63. data/lib/public/javascripts/plupload-rails3/plupload/js/plupload.flash.swf +0 -0
  64. data/lib/public/javascripts/plupload-rails3/plupload/js/plupload.full.js +2 -0
  65. data/lib/public/javascripts/plupload-rails3/plupload/js/plupload.gears.js +1 -0
  66. data/lib/public/javascripts/plupload-rails3/plupload/js/plupload.html4.js +1 -0
  67. data/lib/public/javascripts/plupload-rails3/plupload/js/plupload.html5.js +1 -0
  68. data/lib/public/javascripts/plupload-rails3/plupload/js/plupload.js +2 -0
  69. data/lib/public/javascripts/plupload-rails3/plupload/js/plupload.silverlight.js +1 -0
  70. data/lib/public/javascripts/plupload-rails3/plupload/js/plupload.silverlight.xap +0 -0
  71. data/lib/public/javascripts/plupload-rails3/plupload/license.txt +339 -0
  72. data/lib/public/javascripts/plupload-rails3/plupload/readme.md +46 -0
  73. data/lib/public/stylesheets/.DS_Store +0 -0
  74. data/lib/public/stylesheets/.gitkeep +0 -0
  75. data/lib/public/stylesheets/plupload-rails3/jquery-ui.custom.css +578 -0
  76. data/lib/public/stylesheets/plupload-rails3/plupload.queue.3.1.css +171 -0
  77. data/lib/public/stylesheets/plupload-rails3/plupload.queue.css +171 -0
  78. data/lib/tasks/asset_mover.rake +15 -0
  79. data/plupload-rails3.gemspec +24 -0
  80. data/test/plupload_rails3_test.rb +29 -0
  81. data/test/test_helper.rb +3 -0
  82. data/uninstall.rb +3 -0
  83. metadata +131 -0
@@ -0,0 +1,103 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
5
+ <title>Plupload - Queue widget example</title>
6
+ <style type="text/css">
7
+ body {
8
+ font-family:Verdana, Geneva, sans-serif;
9
+ font-size:13px;
10
+ color:#333;
11
+ background:url(../bg.jpg);
12
+ }
13
+ </style>
14
+ <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/base/jquery-ui.css" type="text/css" />
15
+ <link rel="stylesheet" href="../../js/jquery.ui.plupload/css/jquery.ui.plupload.css" type="text/css" />
16
+
17
+ <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
18
+ <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js"></script>
19
+ <script type="text/javascript" src="http://bp.yahooapis.com/2.4.21/browserplus-min.js"></script>
20
+
21
+ <script type="text/javascript" src="../../js/plupload.js"></script>
22
+ <script type="text/javascript" src="../../js/plupload.gears.js"></script>
23
+ <script type="text/javascript" src="../../js/plupload.silverlight.js"></script>
24
+ <script type="text/javascript" src="../../js/plupload.flash.js"></script>
25
+ <script type="text/javascript" src="../../js/plupload.browserplus.js"></script>
26
+ <script type="text/javascript" src="../../js/plupload.html4.js"></script>
27
+ <script type="text/javascript" src="../../js/plupload.html5.js"></script>
28
+ <script type="text/javascript" src="../../js/jquery.ui.plupload/jquery.ui.plupload.js"></script>
29
+
30
+ <!--<script type="text/javascript" src="http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js"></script>-->
31
+ </head>
32
+ <body>
33
+
34
+ <h1>jQuery UI Widget</h1>
35
+
36
+ <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>
37
+
38
+ <form method="post" action="dump.php">
39
+ <div id="uploader">
40
+ <p>You browser doesn't have Flash, Silverlight, Gears, BrowserPlus or HTML5 support.</p>
41
+ </div>
42
+ </form>
43
+ <script type="text/javascript">
44
+ // Convert divs to queue widgets when the DOM is ready
45
+ $(function() {
46
+ $("#uploader").plupload({
47
+ // General settings
48
+ runtimes : 'flash,html5,browserplus,silverlight,gears,html4',
49
+ url : '../upload.php',
50
+ max_file_size : '1000mb',
51
+ max_file_count: 20, // user can add no more then 20 files at a time
52
+ chunk_size : '1mb',
53
+ unique_names : true,
54
+ multiple_queues : true,
55
+
56
+ // Resize images on clientside if we can
57
+ resize : {width : 320, height : 240, quality : 90},
58
+
59
+ // Rename files by clicking on their titles
60
+ rename: true,
61
+
62
+ // Sort files
63
+ sortable: true,
64
+
65
+ // Specify what files to browse for
66
+ filters : [
67
+ {title : "Image files", extensions : "jpg,gif,png"},
68
+ {title : "Zip files", extensions : "zip,avi"}
69
+ ],
70
+
71
+ // Flash settings
72
+ flash_swf_url : '../../js/plupload.flash.swf',
73
+
74
+ // Silverlight settings
75
+ silverlight_xap_url : '../../js/plupload.silverlight.xap'
76
+ });
77
+
78
+ // Client side form validation
79
+ $('form').submit(function(e) {
80
+ var uploader = $('#uploader').plupload('getUploader');
81
+
82
+ // Validate number of uploaded files
83
+ if (uploader.total.uploaded == 0) {
84
+ // Files in queue upload them first
85
+ if (uploader.files.length > 0) {
86
+ // When all files are uploaded submit form
87
+ uploader.bind('UploadProgress', function() {
88
+ if (uploader.total.uploaded == uploader.files.length)
89
+ $('form').submit();
90
+ });
91
+
92
+ uploader.start();
93
+ } else
94
+ alert('You must at least upload one file.');
95
+
96
+ e.preventDefault();
97
+ }
98
+ });
99
+
100
+ });
101
+ </script>
102
+ </body>
103
+ </html>
@@ -0,0 +1,174 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
5
+ <title>Plupload - Queue widget example</title>
6
+ <style type="text/css">
7
+ body {
8
+ font-family:Verdana, Geneva, sans-serif;
9
+ font-size:13px;
10
+ color:#333;
11
+ background:url(../bg.jpg);
12
+ }
13
+ </style>
14
+ <link rel="stylesheet" href="../../js/jquery.plupload.queue/css/jquery.plupload.queue.css" type="text/css" media="screen" />
15
+
16
+ <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
17
+ <script type="text/javascript" src="http://bp.yahooapis.com/2.4.21/browserplus-min.js"></script>
18
+
19
+ <script type="text/javascript" src="../../js/plupload.js"></script>
20
+ <script type="text/javascript" src="../../js/plupload.gears.js"></script>
21
+ <script type="text/javascript" src="../../js/plupload.silverlight.js"></script>
22
+ <script type="text/javascript" src="../../js/plupload.flash.js"></script>
23
+ <script type="text/javascript" src="../../js/plupload.browserplus.js"></script>
24
+ <script type="text/javascript" src="../../js/plupload.html4.js"></script>
25
+ <script type="text/javascript" src="../../js/plupload.html5.js"></script>
26
+ <script type="text/javascript" src="../../js/jquery.plupload.queue/jquery.plupload.queue.js"></script>
27
+
28
+ <!-- <script type="text/javascript" src="http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js"></script> -->
29
+ </head>
30
+ <body>
31
+
32
+ <form method="post" action="dump.php">
33
+ <h1>Queue widget example</h1>
34
+
35
+ <p>Shows the jQuery Plupload Queue widget and under different runtimes.</p>
36
+
37
+ <div style="float: left; margin-right: 20px">
38
+ <h3>Flash runtime</h3>
39
+ <div id="flash_uploader" style="width: 450px; height: 330px;">You browser doesn't have Flash installed.</div>
40
+
41
+ <h3>Gears runtime</h3>
42
+ <div id="gears_uploader" style="width: 450px; height: 330px;">You browser doesn't have Gears installed.</div>
43
+ </div>
44
+
45
+ <div style="float: left; margin-right: 20px">
46
+ <h3>Silverlight runtime</h3>
47
+ <div id="silverlight_uploader" style="width: 450px; height: 330px;">You browser doesn't have Silverlight installed.</div>
48
+
49
+ <h3>HTML 5 runtime</h3>
50
+ <div id="html5_uploader" style="width: 450px; height: 330px;">You browser doesn't support native upload. Try Firefox 3 or Safari 4.</div>
51
+ </div>
52
+
53
+ <div style="float: left; margin-right: 20px">
54
+ <h3>BrowserPlus runtime</h3>
55
+ <div id="browserplus_uploader" style="width: 450px; height: 330px;">You browser doesn't have BrowserPlus installed.</div>
56
+
57
+ <h3>HTML 4 runtime</h3>
58
+ <div id="html4_uploader" style="width: 450px; height: 330px;">You browser doesn't have HTML 4 support.</div>
59
+ </div>
60
+
61
+ <br style="clear: both" />
62
+
63
+ <input type="submit" value="Send" />
64
+ </form>
65
+
66
+ <script type="text/javascript">
67
+ $(function() {
68
+ // Setup flash version
69
+ $("#flash_uploader").pluploadQueue({
70
+ // General settings
71
+ runtimes : 'flash',
72
+ url : '../upload.php',
73
+ max_file_size : '10mb',
74
+ chunk_size : '1mb',
75
+ unique_names : true,
76
+ filters : [
77
+ {title : "Image files", extensions : "jpg,gif,png"},
78
+ {title : "Zip files", extensions : "zip"}
79
+ ],
80
+
81
+ // Resize images on clientside if we can
82
+ resize : {width : 320, height : 240, quality : 90},
83
+
84
+ // Flash settings
85
+ flash_swf_url : '../../js/plupload.flash.swf'
86
+ });
87
+
88
+ // Setup gears version
89
+ $("#gears_uploader").pluploadQueue({
90
+ // General settings
91
+ runtimes : 'gears',
92
+ url : 'upload.php',
93
+ max_file_size : '10mb',
94
+ chunk_size : '1mb',
95
+ unique_names : true,
96
+ filters : [
97
+ {title : "Image files", extensions : "jpg,gif,png"},
98
+ {title : "Zip files", extensions : "zip"}
99
+ ],
100
+
101
+ // Resize images on clientside if we can
102
+ resize : {width : 320, height : 240, quality : 90}
103
+ });
104
+
105
+ // Setup silverlight version
106
+ $("#silverlight_uploader").pluploadQueue({
107
+ // General settings
108
+ runtimes : 'silverlight',
109
+ url : 'upload.php',
110
+ max_file_size : '10mb',
111
+ chunk_size : '1mb',
112
+ unique_names : true,
113
+ filters : [
114
+ {title : "Image files", extensions : "jpg,gif,png"},
115
+ {title : "Zip files", extensions : "zip"}
116
+ ],
117
+
118
+ // Resize images on clientside if we can
119
+ resize : {width : 320, height : 240, quality : 90},
120
+
121
+ // Silverlight settings
122
+ silverlight_xap_url : '../../js/plupload.silverlight.xap'
123
+ });
124
+
125
+ // Setup html5 version
126
+ $("#html5_uploader").pluploadQueue({
127
+ // General settings
128
+ runtimes : 'html5',
129
+ url : 'upload.php',
130
+ max_file_size : '10mb',
131
+ chunk_size : '1mb',
132
+ unique_names : true,
133
+ filters : [
134
+ {title : "Image files", extensions : "jpg,gif,png"},
135
+ {title : "Zip files", extensions : "zip"}
136
+ ],
137
+
138
+ // Resize images on clientside if we can
139
+ resize : {width : 320, height : 240, quality : 90}
140
+ });
141
+
142
+ // Setup browserplus version
143
+ $("#browserplus_uploader").pluploadQueue({
144
+ // General settings
145
+ runtimes : 'browserplus',
146
+ url : 'upload.php',
147
+ max_file_size : '10mb',
148
+ chunk_size : '1mb',
149
+ unique_names : true,
150
+ filters : [
151
+ {title : "Image files", extensions : "jpg,gif,png"},
152
+ {title : "Zip files", extensions : "zip"}
153
+ ],
154
+
155
+ // Resize images on clientside if we can
156
+ resize : {width : 320, height : 240, quality : 90}
157
+ });
158
+
159
+ // Setup html4 version
160
+ $("#html4_uploader").pluploadQueue({
161
+ // General settings
162
+ runtimes : 'html4',
163
+ url : 'upload.php',
164
+ unique_names : true,
165
+ filters : [
166
+ {title : "Image files", extensions : "jpg,gif,png"},
167
+ {title : "Zip files", extensions : "zip"}
168
+ ]
169
+ });
170
+ });
171
+ </script>
172
+
173
+ </body>
174
+ </html>
@@ -0,0 +1,158 @@
1
+ <?php
2
+ /*
3
+ In order to upload files to S3 using Flash runtime, one should start by placing crossdomain.xml into the bucket.
4
+ crossdomain.xml can be as simple as this:
5
+
6
+ <?xml version="1.0"?>
7
+ <!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
8
+ <cross-domain-policy>
9
+ <allow-access-from domain="*" secure="false" />
10
+ </cross-domain-policy>
11
+
12
+ In our tests SilverLight didn't require anything special and worked with this configuration just fine. It may fail back
13
+ to the same crossdomain.xml as last resort.
14
+
15
+ !!!Important!!! Plupload UI Widget here, is used only for demo purposes and is not required for uploading to S3.
16
+ */
17
+
18
+ // important variables that will be used throughout this example
19
+ $bucket = 'BUCKET';
20
+
21
+ // these can be found on your Account page, under Security Credentials > Access Keys
22
+ $accessKeyId = 'ACCESS_KEY_ID';
23
+ $secret = 'SECRET_ACCESS_KEY';
24
+
25
+
26
+ // hash_hmac — Generate a keyed hash value using the HMAC method
27
+ // (PHP 5 >= 5.1.2, PECL hash >= 1.1)
28
+ if (!function_exists('hash_hmac')) :
29
+ // based on: http://www.php.net/manual/en/function.sha1.php#39492
30
+ function hash_hmac($algo, $data, $key, $raw_output = false)
31
+ {
32
+ $blocksize = 64;
33
+ if (strlen($key) > $blocksize)
34
+ $key = pack('H*', $algo($key));
35
+
36
+ $key = str_pad($key, $blocksize, chr(0x00));
37
+ $ipad = str_repeat(chr(0x36), $blocksize);
38
+ $opad = str_repeat(chr(0x5c), $blocksize);
39
+ $hmac = pack('H*', $algo(($key^$opad) . pack('H*', $algo(($key^$ipad) . $data))));
40
+
41
+ return $raw_output ? $hmac : bin2hex($hmac);
42
+ }
43
+ endif;
44
+
45
+ // prepare policy
46
+ $policy = base64_encode(json_encode(array(
47
+ // ISO 8601 - date('c'); generates uncompatible date, so better do it manually
48
+ 'expiration' => date('Y-m-d\TH:i:s.000\Z', strtotime('+1 day')),
49
+ 'conditions' => array(
50
+ array('bucket' => $bucket),
51
+ array('acl' => 'public-read'),
52
+ array('starts-with', '$key', ''),
53
+ // for demo purposes we are accepting only images
54
+ array('starts-with', '$Content-Type', 'image/'),
55
+ // "Some versions of the Adobe Flash Player do not properly handle HTTP responses that have an empty body.
56
+ // To configure POST to return a response that does not have an empty body, set success_action_status to 201.
57
+ // When set, Amazon S3 returns an XML document with a 201 status code."
58
+ // http://docs.amazonwebservices.com/AmazonS3/latest/dev/HTTPPOSTFlash.html
59
+ array('success_action_status' => '201'),
60
+ // Plupload internally adds name field, so we need to mention it here
61
+ array('starts-with', '$name', ''),
62
+ // One more field to take into account: Filename - gets silently sent by FileReference.upload() in Flash
63
+ // http://docs.amazonwebservices.com/AmazonS3/latest/dev/HTTPPOSTFlash.html
64
+ array('starts-with', '$Filename', ''),
65
+ )
66
+ )));
67
+
68
+ // sign policy
69
+ $signature = base64_encode(hash_hmac('sha1', $policy, $secret, true));
70
+
71
+ ?>
72
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
73
+ <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
74
+ <head>
75
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
76
+ <title>Plupload to Amazon S3 Example</title>
77
+
78
+ <style type="text/css">
79
+ body {
80
+ font-family:Verdana, Geneva, sans-serif;
81
+ font-size:13px;
82
+ color:#333;
83
+ background:url(../bg.jpg);
84
+ }
85
+ </style>
86
+
87
+ <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/base/jquery-ui.css" type="text/css" />
88
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
89
+ <script src=" https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js"></script>
90
+
91
+ <!-- Load plupload and all it's runtimes and finally the UI widget -->
92
+ <link rel="stylesheet" href="../../js/jquery.ui.plupload/css/jquery.ui.plupload.css" type="text/css" />
93
+
94
+ <script type="text/javascript" src="../../js/plupload.js"></script>
95
+ <script type="text/javascript" src="../../js/plupload.gears.js"></script>
96
+ <script type="text/javascript" src="../../js/plupload.silverlight.js"></script>
97
+ <script type="text/javascript" src="../../js/plupload.flash.js"></script>
98
+ <script type="text/javascript" src="../../js/plupload.browserplus.js"></script>
99
+ <script type="text/javascript" src="../../js/plupload.html4.js"></script>
100
+ <script type="text/javascript" src="../../js/plupload.html5.js"></script>
101
+ <script type="text/javascript" src="../../js/jquery.ui.plupload/jquery.ui.plupload.js"></script>
102
+ <!--<script type="text/javascript" src="http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js"></script>-->
103
+
104
+ </head>
105
+ <body>
106
+
107
+ <h1>Plupload to Amazon S3 Example</h1>
108
+
109
+ <div id="uploader">
110
+ <p>You browser doesn't have Flash, Silverlight, Gears, BrowserPlus or HTML5 support.</p>
111
+ </div>
112
+
113
+ <script type="text/javascript">
114
+ // Convert divs to queue widgets when the DOM is ready
115
+ $(function() {
116
+ $("#uploader").plupload({
117
+ runtimes : 'flash,silverlight',
118
+ url : 'http://<?php echo $bucket; ?>.s3.amazonaws.com/',
119
+ max_file_size : '10mb',
120
+
121
+ multipart: true,
122
+ multipart_params: {
123
+ 'key': '${filename}', // use filename as a key
124
+ 'Filename': '${filename}', // adding this to keep consistency across the runtimes
125
+ 'acl': 'public-read',
126
+ 'Content-Type': 'image/jpeg',
127
+ 'success_action_status': '201',
128
+ 'AWSAccessKeyId' : '<?php echo $accessKeyId; ?>',
129
+ 'policy': '<?php echo $policy; ?>',
130
+ 'signature': '<?php echo $signature; ?>'
131
+ },
132
+
133
+ // !!!Important!!!
134
+ // this is not recommended with S3, since it will force Flash runtime into the mode, with no progress indication
135
+ //resize : {width : 800, height : 600, quality : 60}, // Resize images on clientside, if possible
136
+
137
+ // optional, but better be specified directly
138
+ file_data_name: 'file',
139
+
140
+ // re-use widget (not related to S3, but to Plupload UI Widget)
141
+ multiple_queues: true,
142
+
143
+ // Specify what files to browse for
144
+ filters : [
145
+ {title : "JPEG files", extensions : "jpg"}
146
+ ],
147
+
148
+ // Flash settings
149
+ flash_swf_url : '../../js/plupload.flash.swf',
150
+
151
+ // Silverlight settings
152
+ silverlight_xap_url : '../../js/plupload.silverlight.xap'
153
+ });
154
+ });
155
+ </script>
156
+
157
+ </body>
158
+ </html>
@@ -0,0 +1,124 @@
1
+ <?php
2
+ /**
3
+ * upload.php
4
+ *
5
+ * Copyright 2009, Moxiecode Systems AB
6
+ * Released under GPL License.
7
+ *
8
+ * License: http://www.plupload.com/license
9
+ * Contributing: http://www.plupload.com/contributing
10
+ */
11
+
12
+ // HTTP headers for no cache etc
13
+ header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
14
+ header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
15
+ header("Cache-Control: no-store, no-cache, must-revalidate");
16
+ header("Cache-Control: post-check=0, pre-check=0", false);
17
+ header("Pragma: no-cache");
18
+
19
+ // Settings
20
+ //$targetDir = ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . "plupload";
21
+ $targetDir = 'uploads/';
22
+
23
+ //$cleanupTargetDir = false; // Remove old files
24
+ //$maxFileAge = 60 * 60; // Temp file age in seconds
25
+
26
+ // 5 minutes execution time
27
+ @set_time_limit(5 * 60);
28
+
29
+ // Uncomment this one to fake upload time
30
+ // usleep(5000);
31
+
32
+ // Get parameters
33
+ $chunk = isset($_REQUEST["chunk"]) ? $_REQUEST["chunk"] : 0;
34
+ $chunks = isset($_REQUEST["chunks"]) ? $_REQUEST["chunks"] : 0;
35
+ $fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : '';
36
+
37
+ // Clean the fileName for security reasons
38
+ $fileName = preg_replace('/[^\w\._]+/', '', $fileName);
39
+
40
+ // Make sure the fileName is unique but only if chunking is disabled
41
+ if ($chunks < 2 && file_exists($targetDir . DIRECTORY_SEPARATOR . $fileName)) {
42
+ $ext = strrpos($fileName, '.');
43
+ $fileName_a = substr($fileName, 0, $ext);
44
+ $fileName_b = substr($fileName, $ext);
45
+
46
+ $count = 1;
47
+ while (file_exists($targetDir . DIRECTORY_SEPARATOR . $fileName_a . '_' . $count . $fileName_b))
48
+ $count++;
49
+
50
+ $fileName = $fileName_a . '_' . $count . $fileName_b;
51
+ }
52
+
53
+ // Create target dir
54
+ if (!file_exists($targetDir))
55
+ @mkdir($targetDir);
56
+
57
+ // Remove old temp files
58
+ /* this doesn't really work by now
59
+
60
+ if (is_dir($targetDir) && ($dir = opendir($targetDir))) {
61
+ while (($file = readdir($dir)) !== false) {
62
+ $filePath = $targetDir . DIRECTORY_SEPARATOR . $file;
63
+
64
+ // Remove temp files if they are older than the max age
65
+ if (preg_match('/\\.tmp$/', $file) && (filemtime($filePath) < time() - $maxFileAge))
66
+ @unlink($filePath);
67
+ }
68
+
69
+ closedir($dir);
70
+ } else
71
+ die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}');
72
+ */
73
+
74
+ // Look for the content type header
75
+ if (isset($_SERVER["HTTP_CONTENT_TYPE"]))
76
+ $contentType = $_SERVER["HTTP_CONTENT_TYPE"];
77
+
78
+ if (isset($_SERVER["CONTENT_TYPE"]))
79
+ $contentType = $_SERVER["CONTENT_TYPE"];
80
+
81
+ // Handle non multipart uploads older WebKit versions didn't support multipart in HTML5
82
+ if (strpos($contentType, "multipart") !== false) {
83
+ if (isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
84
+ // Open temp file
85
+ $out = fopen($targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab");
86
+ if ($out) {
87
+ // Read binary input stream and append it to temp file
88
+ $in = fopen($_FILES['file']['tmp_name'], "rb");
89
+
90
+ if ($in) {
91
+ while ($buff = fread($in, 4096))
92
+ fwrite($out, $buff);
93
+ } else
94
+ die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
95
+ fclose($in);
96
+ fclose($out);
97
+ @unlink($_FILES['file']['tmp_name']);
98
+ } else
99
+ die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
100
+ } else
101
+ die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}');
102
+ } else {
103
+ // Open temp file
104
+ $out = fopen($targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab");
105
+ if ($out) {
106
+ // Read binary input stream and append it to temp file
107
+ $in = fopen("php://input", "rb");
108
+
109
+ if ($in) {
110
+ while ($buff = fread($in, 4096))
111
+ fwrite($out, $buff);
112
+ } else
113
+ die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
114
+
115
+ fclose($in);
116
+ fclose($out);
117
+ } else
118
+ die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
119
+ }
120
+
121
+ // Return JSON-RPC response
122
+ die('{"jsonrpc" : "2.0", "result" : null, "id" : "id"}');
123
+
124
+ ?>