forked from tpyo/amazon-s3-php-class
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example-form.php
66 lines (54 loc) · 1.94 KB
/
example-form.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
<?php
/**
* $Id$
*
* S3 form upload example
*/
if (!class_exists('S3')) require_once 'S3.php';
// AWS access info
if (!defined('awsAccessKey')) define('awsAccessKey', 'change-this');
if (!defined('awsSecretKey')) define('awsSecretKey', 'change-this');
// Check for CURL
if (!extension_loaded('curl') && !@dl(PHP_SHLIB_SUFFIX == 'so' ? 'curl.so' : 'php_curl.dll'))
exit("\nERROR: CURL extension not loaded\n\n");
// Pointless without your keys!
if (awsAccessKey == 'change-this' || awsSecretKey == 'change-this')
exit("\nERROR: AWS access information required\n\nPlease edit the following lines in this file:\n\n".
"define('awsAccessKey', 'change-me');\ndefine('awsSecretKey', 'change-me');\n\n");
S3::setAuth(awsAccessKey, awsSecretKey);
$bucket = 'upload-bucket';
$path = 'myfiles/'; // Can be empty ''
$lifetime = 3600; // Period for which the parameters are valid
$maxFileSize = (1024 * 1024 * 50); // 50 MB
$metaHeaders = array('uid' => 123);
$requestHeaders = array(
'Content-Type' => 'application/octet-stream',
'Content-Disposition' => 'attachment; filename=${filename}'
);
$params = S3::getHttpUploadPostParams(
$bucket,
$path,
S3::ACL_PUBLIC_READ,
$lifetime,
$maxFileSize,
201, // Or a URL to redirect to on success
$metaHeaders,
$requestHeaders,
false // False since we're not using flash
);
$uploadURL = 'https://' . $bucket . '.s3.amazonaws.com/';
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>S3 Form Upload</title>
</head>
<body>
<form method="post" action="<?php echo $uploadURL; ?>" enctype="multipart/form-data">
<?php
foreach ($params as $p => $v)
echo " <input type=\"hidden\" name=\"{$p}\" value=\"{$v}\" />\n";
?>
<input type="file" name="file" /> <input type="submit" value="Upload" />
</form>
</body>
</html>