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

zahedkamal87's avatar

Getting erros while I try to upload CSS or PHP files

I'm trying to upload a CSS and PHP file. CSS file uploads in "livewire-tmp" as ".txt" file extension, but shows validation saying to select "css" file. And, if i try to upload PHP file, I get error saying - "Unable to retrieve the file_size for file at location: livewire-tmp. " in livewire-error iframe.

How can I fix this issue? Below is the code snippet of the component. Thank you

<?php
use Livewire\Attributes\Layout;
use Livewire\Attributes\Title;
use Livewire\Volt\Component;
use Livewire\WithFileUploads;
use Livewire\Attributes\Validate;

new
#[Layout('layouts.guest')]
#[Title('Code Editor')]
class extends Component {
    use WithFileUploads;

    #[Validate('mimes:css,php|max:2048')]
    public $import_file;

}; ?>

<div class="container py-5">
    <div class="btn-toolbar justify-content-center mb-3" style="gap: 5px 10px;">
        <label class="btn btn-primary">
            Load from File
            <input class="d-none" wire:model='import_file' name='import_file' type="file" accept=".css,.php">
        </label>

        @error('import_file')
            <p class="text-danger mb-0 mt-1 small">{{ $message }}</p>
        @enderror
    </div>

	<textarea class="form-control"></textarea>
</div>
0 likes
5 replies
JussiMannisto's avatar

Uploading PHP files is blocked as a security measure. And for a very good reason.

JussiMannisto's avatar

@zahedkamal87 I don't know exactly. But as a baseline I wouldn't allow user uploads of any files that might be interpreted by a browser. It might contain stuff like:

body {
	background-image: url('https://malicious-site.com/tracking-shenanigans.php');
}

You might be able to do something much worse but I haven't looked into it.

Snapey's avatar

I think you have to whitelist additional mime types in the livewire config file

zahedkamal87's avatar

@Snapey whitelist where/how? There is no such option in config\livewire.php. But, if you mean 'preview_mimes', added there, but still the same issue.

Please or to participate in this conversation.