Try this maybe: https://stackoverflow.com/a/44577640/1457270
Feb 24, 2022
13
Level 12
Nothing happens when trying to ->move() a file to the public folder
Hey!
I'm trying to upload files into public folder but without success. Here's what I'm trying to do:
$request->validate([
'formNormal' => 'mimes:jpg,jpeg,png,svg',
'formSticky' => 'mimes:jpg,jpeg,png,svg',
]);
if($request->hasFile('formNormal')) {
$image = file_get_contents($request->formNormal);
$image->move(public_path('assets/img'), 'logo.' . $requets->formNormal->getClientOriginalExtension());
}
if($request->hasFile('formSticky')) {
$image = file_get_contents($request->formSticky);
$image->move(public_path('assets/img'), 'logo_sticky.' . $requets->formSticky->getClientOriginalExtension());
}
View:
<form action="{{ url('administrator/save/logo/changes') }}" method="POST" enctype="multipart/form-data">
<input class="form-control" name="formNormal" type="file" id="formNormal">
<input class="form-control" name="formSticky" type="file" id="formSticky">
</form>
What am I doing wrong? Also does ->move() override if the file exists?
Level 73
@Laralex this is my last try:
Change the filesystem path to this:
'public_assets_img' => [
'driver' => 'local',
'root' => public_path() . '/assets',
'visibility' => 'public',
],
then use it:
if($request->hasFile('formNormal')) {
$request->file('formNormal')->storeAs('img', 'logo.' . $request->file('formNormal')->extension(), 'public_assets_img');
}
Please or to participate in this conversation.