Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not lowercase my filename when uploading assets. #1198

Open
geertjanknapen1 opened this issue Jul 12, 2024 · 3 comments
Open

Do not lowercase my filename when uploading assets. #1198

geertjanknapen1 opened this issue Jul 12, 2024 · 3 comments

Comments

@geertjanknapen1
Copy link

For a project, I need to be able to display assets in the browser (they are PDF files).
Due to these PDF files being technical documents, there are already QR codes made for these files (mywebsite.test/files/MyFile.pdf)

As you can see they are camel-cased.

When uploading an asset, Statamic does: in_array(trim(strtolower($file->getClientOriginalExtension())), $extensions).
So I cannot upload files with uppercased characters in the filename.
For me, this is an issue at the moment, but it's pretty niche of course.

I would like to propose a new setting on the asset container that makes us able to toggle between allowing and disallowing uppercased characters? Of course defaulting to uppercase not allowed.

Again, this is a niche problem, but maybe something other people will run into as well.


Where the code is located: src/Validation/AllowedFile/IsAllowed()

It looks like this;

private function isAllowed(UploadedFile $file): bool
{
    $extensions = array_merge($this->extensions, config('statamic.assets.additional_uploadable_extensions', []));

    return in_array(trim(strtolower($file->getClientOriginalExtension())), $extensions);
}
@duncanmcclean
Copy link
Member

duncanmcclean commented Jul 12, 2024

You can opt-out of filenames being converted to lowercase, by toggling the lowercase config option in your config/statamic/assets.php config file.

/*
|--------------------------------------------------------------------------
| Enforce Lowercase Filenames
|--------------------------------------------------------------------------
|
| Control whether asset filenames will be converted to lowercase when
| uploading and renaming. This can help you avoid file conflicts
| when working in case-insensitive filesystem environments.
|
*/

'lowercase' => true,

@geertjanknapen1
Copy link
Author

But that wouldn't be on an asset container-based level, right?
If I set this to false it would happen for all my containers, right?

@duncanmcclean
Copy link
Member

Correct.

There's currently no way to set it on a per-container basis. Good idea though!

@duncanmcclean duncanmcclean reopened this Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants