Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

eriktobben's avatar

Problem storing file in folder DO/S3

Hi,

I am using the following code to store a public file in Digital Ocean Spaces:

Storage::disk('spaces')->put("img/category/{$fileName}.{$fileContents->extension()}", $fileContents, 'public');

But this is how it is being stored in DO: BUCKET/img/category/8a18ad92-5646-4676-83a1-989a8ec222da-test.jpeg/3RmP6iFEbNx5uF2Jr27ONqL5Apl8gVLKUXLzpVbh.jpeg

So my file name becomes a folder. How can I specify what folder to store the file in and set a custom file name?

0 likes
1 reply
eriktobben's avatar

The following code work as expected:

$storage = \Storage::disk('spaces');
$filePath = "img/category/{$fileName}.{$fileContents->extension()}";
$storage->put($filePath, file_get_contents($fileContents), 'public');

Please or to participate in this conversation.