Skip to content

Instantly share code, notes, and snippets.

@conkonig
Created June 10, 2022 17:02
Show Gist options
  • Save conkonig/7ebd5ea70f4a1f1f8480b9a921bcde81 to your computer and use it in GitHub Desktop.
Save conkonig/7ebd5ea70f4a1f1f8480b9a921bcde81 to your computer and use it in GitHub Desktop.
Upload a file to DO Spaces
<?php
require_once __DIR__ . '/vendor/autoload.php';
// using composer "sociallydev/spaces-api": "3.5"
use \SpacesAPI\Spaces;
$spaces = new Spaces('apikey', 'secret');
$space = $spaces->space('bucket');
$filename = 'image.png';
$file = $space->uploadFile($img, $filename);
$file->makePublic();
$fileurl = $file->getURL();
echo '<img src="' . $fileurl . '" width="200" height="auto" />';
?>
<a href="<?php echo $fileurl; ?>"><?php echo $fileurl; ?></a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment