-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
63 lines (58 loc) · 2.01 KB
/
index.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
<?php
require __DIR__ . '/vendor/autoload.php';
use Intervention\Image\ImageManagerStatic as Image;
use Google\Cloud\Storage\StorageClient;
Image::configure();
$storage = new StorageClient([
'keyFile' => json_decode(file_get_contents('keyfile.json'), true)
]);
$bucket = $storage->bucket('auctioncliq');
@ini_set('upload_max_size', '10M');
@ini_set('post_max_size', '12M');
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: *");
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
$target_dir = "";
$uploadOk = 0;
var_dump('init');
var_dump($_FILES);
die();
if ($_FILES) {
$newname = basename($_FILES["fileToUpload"]["name"]);
if (isset($_POST['newnamewithextension']) && $_POST['newnamewithextension']) {
$newname = $_POST['newnamewithextension'];
}
$target_file = $target_dir . $newname;
$filename = pathinfo($target_file, PATHINFO_FILENAME);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));
// Allow certain file formats
if (
$imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif"
) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
$img = Image::make($_FILES['fileToUpload']['tmp_name']);
// resize image
$img->fit(300, 200);
// $img->backup();
// save image
// $img->encode('jpg', 90)->save($filename . '.jpg');
// $img->reset();
$webp = $img->stream('webp', 80);
// var_dump($webp->__toString());
// die();
$upload = $bucket->upload($webp, ['name' => $filename . '.webp', 'metadata' => ['contentType' => 'image/webp']]);
// var_dump($upload);
echo 'file saved';
}
} else {
echo "No files attached";
}