-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathputfile.php
More file actions
62 lines (48 loc) · 1.4 KB
/
putfile.php
File metadata and controls
62 lines (48 loc) · 1.4 KB
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
<?php
require 'aws/aws-autoloader.php';
require 'config.php';
use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;
if(isset($_GET['id'])){
$id = $_GET['id']*1;
$query = "SELECT * FROM media WHERE id = $id AND stored = 0 LIMIT 1 FOR UPDATE";
$result = mysqli_query($link,$query);
while ($row = mysqli_fetch_array($result)) {
$bucket = "".HB_BUCKET."";
$keyname = $row['name'];
// $filepath should be absolute path to a file on disk
$filePath = "".PL_ABS_URL."/media/files/".$row['name']."";
// Instantiate the client.
$s3 = new S3Client([
'version' => 'latest',
'region' => 'ru-msk',
'credentials' => [
'key' => "".HB_ACCESSKEY."",
'secret' => "".HB_SECRETKEY."",
],
'endpoint' => "".HB_ENDPOINT.""
]);
try {
// Upload data.
$results3 = $s3->putObject(array(
'Bucket' => $bucket,
'Key' => $keyname,
'SourceFile' => $filePath,
'ACL' => 'public-read',
'ContentType' => 'video/mp4'
));
echo $results3['@metadata']["statusCode"]. "\n";
echo $id . "\n";
// Print the URL to the object.
echo $results3['ObjectURL'] . "\n";
}
catch (S3Exception $e) {
echo $e->getMessage() . "\n";
}
echo $row['name']."<br />";
echo $row['id']."<br />";
mysqli_query($link,"UPDATE media SET stored=1 WHERE id='".$row['id']."'");
header("location: index.php");
}
mysqli_close($link);
}