Uploading PHP files is blocked as a security measure. And for a very good reason.
Jun 9, 2024
5
Level 2
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>
Please or to participate in this conversation.