-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathexample-form.php
executable file
·78 lines (63 loc) · 2.15 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
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/**
* $Id$
*
* SCS form upload example
*/
//you can ignore it
@include_once('config.php');
if (!class_exists('SCS')) require_once '../class/SCS.php';
date_default_timezone_set('UTC');
// SCS access info
if (!defined('AccessKey')) define('AccessKey', 'change-this');
if (!defined('SecretKey')) define('SecretKey', 'change-this');
if (!defined('BucketName')) define('BucketName', '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 (AccessKey == 'change-this' || SecretKey == 'change-this')
exit("\nERROR: SCS access information required\n\nPlease edit the following lines in this file:\n\n".
"define('AccessKey', 'change-me');\ndefine('SecretKey', 'change-me');\n\n");
// Pointless without your BucketName!
if (BucketName == 'change-this')
exit("\nERROR: BucketName required\n\nPlease edit the following lines in this file:\n\n".
"define('BucketName', 'change-me');\n\n");
SCS::setAuth(AccessKey, SecretKey);
$bucket = BucketName;
$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 = SCS::getHttpUploadPostParams(
$bucket,
$path,
SCS::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 = 'http://' . $bucket . '.sinacloud.net/';
?><!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<title>SCS 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>