-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.php
39 lines (35 loc) · 1.06 KB
/
upload.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
<?php
// require Uploadcare API
require_once 'vendor/autoload.php';
// Define uploadcare account keys
define('UC_PUBLIC_KEY', 'demopublickey');
define('UC_SECRET_KEY', 'demoprivatekey');
use \Uploadcare;
// create an API instance
$api = new Uploadcare\Api(UC_PUBLIC_KEY, UC_SECRET_KEY);
// Count of uploaded files
$filesCount = count($_FILES['upload']['name']);
if($filesCount) {
echo '<h3> Files just uploaded </h3>';
} else {
echo 'No files uploaded';
}
for( $i=0 ; $i < $filesCount ; $i++ ) {
//Get temp file path
$tmpPath = $_FILES['upload']['tmp_name'][$i];
//Make sure we have a file path
if ($tmpPath != ""){
//Setting up the dest file name
$destFilePath = "./uploads/" . $_FILES['upload']['name'][$i];
move_uploaded_file($tmpPath, $destFilePath);
$file = $api->uploader->fromPath($destFilePath);
$file->store();
echo '<p><a href="'.$file->getUrl().'">';
if($file->data['is_image']) {
echo '<img src="'.$file->preview(300, 300)->getUrl().'"><br/>';
}
echo $_FILES['upload']['name'][$i];
echo '</a></p>';
}
}
?>