-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathfilelink-with-security.php
38 lines (29 loc) · 1.03 KB
/
filelink-with-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
<?php
use Filestack\FilestackClient;
use Filestack\FilestackSecurity;
use Filestack\Filelink;
use Filestack\FilestackException;
$test_api_key = 'YOUR_FILESTACK_API_KEY';
$test_secret = 'YOUR_FILESTACK_SECURITY_SECRET';
$test_filepath = __DIR__ . '/../tests/testfiles/calvinandhobbes.jpg';
// upload a file to test
$security = new FilestackSecurity($test_secret);
$client = new FilestackClient($test_api_key, $security);
$uploaded_filelink = $client->upload($test_filepath);
# Filestack client examples
$file_handle = $uploaded_filelink->handle;
$filelink = new Filelink($file_handle,
$test_api_key, $security);
// get metadata
$metadata = $filelink->getMetaData();
// get content of a file
$content = $filelink->getContent();
// save file to local drive
$filepath = __DIR__ . '/../tests/testfiles/' . $metadata['filename'];
file_put_contents($filepath, $content);
// download a file
$filelink->download($test_filepath);
// overwrite remote file with local file
$filelink->overwrite($test_filepath);
// delete remote file
$filelink->delete();