-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathclient-no-security.php
46 lines (37 loc) · 1.22 KB
/
client-no-security.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
<?php
use Filestack\FilestackClient;
use Filestack\Filelink;
use Filestack\FilestackException;
$test_api_key = 'YOUR_FILESTACK_API_KEY';
$test_filepath = __DIR__ . '/../tests/testfiles/calvinandhobbes.jpg';
# Filestack client examples
$client = new FilestackClient($test_api_key);
// upload a file
$filelink = null;
try {
$filelink = $client->upload($test_filepath);
var_dump($filelink);
} catch (FilestackException $e) {
echo $e->getMessage();
echo $e->getCode();
}
// get metadata of file
$fields = [];
$metadata = $client->getMetaData($filelink->handle, $fields);
# or
$metadata = $client->getMetaData($filelink->url(), $fields);
var_dump($metadata);
// get content of a file
$content = $client->getContent($filelink->handle);
# or
$content = $client->getContent($filelink->url());
// save file to local drive
$filepath = __DIR__ . '/../tests/testfiles/' . $metadata['filename'];
file_put_contents($filepath, $content);
// download a file
$destination = __DIR__ . '/../tests/testfiles/my-custom-filename.jpg';
$result = $client->download($filelink->handle, $destination);
# or
$result = $client->download($filelink->url(), $destination);
var_dump($result);
/* overwrite() and delete() require security settings turned on */