I normally put secure files somewhere else in the file system nowhere web related.
Then I have some digits in the file name that has to match the authenticated users ID.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am using a digital ocean spaces account which I believe has the same api as S3. I am wondering how I can protect the files from public download. I have some large 2 gig or more zip files I will need to protect. I will want the user to be able to download them from the website.
This is example code I use to store the file
$path=$s3->put('/albums', request()->file, 'public');
@loach You don’t want to take the “security by obscurity” suggestion. Instead, implement proper authorisation.
S3 allows you to choose the “visibility” of the a file when uploading. A file can either be public (accessible via a URL) or private. Looking at Digital Ocean Spaces’ documentation, it seems to be pretty compatible with S3’s API, so you’ll need to store files with a private ACL when uploading to Spaces.
Upload an Object (PUT) (set the x-amz-acl parameter to private)
When a user wants to download a file, you’ll need to first check if they’re allowed to access the file. This logic belongs in your application. If the user is permitted to access the file, then you should create a pre-signed URL that’s only valid for a predefined length of time. The user should use this URL to access their file. Your application can simply redirect to this URL.
Please or to participate in this conversation.