-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.php
167 lines (149 loc) · 6.42 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
/* Be sure to edit the file included below with your AMAZON S3 settings! */
require_once "config.php";
$isMacUser = (preg_match("/macintosh/",strtolower($_SERVER['HTTP_USER_AGENT'])) ? true : false);
if ( !isset($S3_BUCKET) || $S3_BUCKET == '' ) {
echo "Um, sorry, I need my configuration file. :( ";
exit(0);
}
/*
Flash 10.1 issue, omitted the below from the policy
{"success_action_redirect": "' . $SUCCESS_REDIRECT . '"},
*/
$MAX_FILE_SIZE = 50 * 1048576;
$expTime = time() + (1 * 60 * 60);
$expTimeStr = gmdate('Y-m-d\TH:i:s\Z', $expTime);
$policyDoc = '{
"expiration": "' . $expTimeStr . '",
"conditions": [
{"bucket": "' . $S3_BUCKET . '"},
["starts-with", "$key", ""],
{"acl": "public-read"},
["content-length-range", 0, '. $MAX_FILE_SIZE .'],
{"success_action_status": "201"},
["starts-with", "$Filename", ""],
["starts-with", "$Content-Type", ""]
]
}';
$policyDoc = implode(explode('\r', $policyDoc));
$policyDoc = implode(explode('\n', $policyDoc));
$policyDoc64 = base64_encode($policyDoc);
$sigPolicyDoc = base64_encode(hash_hmac("sha1", $policyDoc64, AWS_SECRET_ACCESS_KEY, TRUE));
?>
<html>
<head>
<title>test Upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<?=$SWFRoot?>swfupload.js"></script>
<script type="text/javascript" src="<?=$SWFRoot?>js/swfupload.queue.js"></script>
<script type="text/javascript" src="<?=$SWFRoot?>js/fileprogress.js"></script>
<script type="text/javascript" src="<?=$SWFRoot?>plugins/swfupload.speed.js"></script>
<script type="text/javascript" src="<?=$SWFRoot?>js/handlers.js"></script>
<script type="text/javascript">
var isMacUser = <?php echo ($isMacUser ? 'true' : 'false'); ?>;
var successURL = '<?php echo ($SUCCESS_REDIRECT); ?>';
var swfu;
window.onload = function () {
swfu = new SWFUpload({
// Backend Settings
//upload_url: "<?php //echo HTTPPATH_MESSAGES.'upload_test.php'?>",
upload_url: "http://<?=$S3_BUCKET?>.s3.amazonaws.com/",
post_params: {"AWSAccessKeyId":"<?=AWS_ACCESS_KEY_ID?>", "key":"${filename}", "acl":"public-read", "policy":"<?=$policyDoc64?>", "signature":"<?=$sigPolicyDoc?>","success_action_status":"201", "content-type":"image/"},
http_success : [201],
assume_success_timeout : <?php echo ($isMacUser ? 5 : 0); ?>,
// File Upload Settings
file_post_name: 'file',
file_size_limit : "102400", // 10 MB
file_types : "*.*",
file_types_description : "All Files",
file_upload_limit : "10",
file_queue_limit : 0,
// Event Handler Settings - these functions as defined in Handlers.js
// The handlers are not part of SWFUpload but are part of my website and control how
// my website reacts to the SWFUpload events.
file_queued_handler : fileQueued,
file_queue_error_handler : fileQueueError,
file_dialog_complete_handler : fileDialogComplete,
upload_start_handler : uploadStart,
upload_progress_handler : uploadProgress,
upload_error_handler : uploadError,
upload_success_handler : uploadSuccess,
upload_complete_handler : uploadComplete,
// Button Settings
button_image_url: "<?=$SWFRoot?>images/TestImageNoText_65x29.png",
button_width: "65",
button_height: "29",
button_placeholder_id: "spanButtonPlaceHolder",
button_text: '<span class="theFont">Browse</span>',
button_text_style: ".theFont { font-size: 16; }",
button_text_left_padding: 6,
button_text_top_padding: 3,
button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
button_cursor: SWFUpload.CURSOR.HAND,
moving_average_history_size: 10,
// Flash Settings
flash_url : "<?=$SWFRoot?>swfupload.swf",
custom_settings : {
progressTarget : "fsUploadProgress",
cancelButtonId : "btnCancel"
},
// Debug Settings
debug: false
});
};
</script>
</head>
<body>
<div id="content">
<form id="form1" action="index.php" method="post" enctype="multipart/form-data">
<p>This page demonstrates a simple usage of SWFUpload. It uses the Queue Plugin to simplify uploading or cancelling all queued files.</p>
<div class="fieldset flash" id="fsUploadProgress">
<span class="legend">Upload Queue</span>
<div id="loadanim" style="display:none;position:relative;top:-10px;line-height:0;"><img src="images/loader.gif" alt="" style="border:0;" /> Processing...please wait.</div>
</div>
<div id="divStatus" style="display:none;">0 Files Uploaded</div>
<div>
<input id="btnCancel" type="button" value="Cancel All Uploads" onClick="swfu.cancelQueue();" disabled="disabled" style="margin-left: 2px; font-size: 8pt; height: 29px;" />
</div>
<span id="spanButtonPlaceHolder"></span>
<!--
<table cellspacing="0">
<tr>
<td>Current Speed:</td>
<td id="tdCurrentSpeed"></td>
</tr>
<tr>
<td>Average Speed:</td>
<td id="tdAverageSpeed"></td>
</tr>
<tr>
<td>Moving Average Speed:</td>
<td id="tdMovingAverageSpeed"></td>
</tr>
<tr>
<td>Time Remaining</td>
<td id="tdTimeRemaining"></td>
</tr>
<tr>
<td>Time Elapsed</td>
<td id="tdTimeElapsed"></td>
</tr>
<tr>
<td>Percent Uploaded</td>
<td id="tdPercentUploaded"></td>
</tr>
<tr>
<td>Size Uploaded</td>
<td id="tdSizeUploaded"></td>
</tr>
<tr>
<td>Progress Event Count</td>
<td id="tdProgressEventCount"></td>
</tr>
</table>
-->
</form>
</div>
</body>
</html>