Jecs9's avatar
Level 1

putFileAs completing but not saving file into my disk/folder

I have been trying to upload images from a form with putFileAs but so far I have not been able to complete the task

I have read that I need to use enctype="multipart/form-data" in the form and I have done it

<form method="POST" action="/blog" enctype="multipart/form-data">
    @csrf
    <div class="field">
        <label class="label col-lg-4" for="header_img">Imagen principal</label>
        <div class="control">
            <input class="input col-lg-8 @error('header_img') is-danger @enderror" type="file" name="header_img" id="header_img">
            @error('header_img')
                <p class="help is-danger">{{ $message }}</p>
            @enderror
        </div>
    </div>
    <div class="field col-lg-4 col-lg-push-10">
        <div class="control">
            <button class="button1" type="submit">Crear</button>
        </div>
    </div>
</form>

On the controller side, I am getting the image, defining a folder to save the image, selecting the disk and passing this information to putFileAs

$file = Storage::disk($disk)->putFileAs($folder, $uploadedFile, $name.'.'.$uploadedFile->getClientOriginalExtension());

I have also logged the variable values

$disk = public
$folder = /images/articles  
$uploadedFile = C:\ProjectPath\php60C2.tmp
$name = 1597289384

I have also logged $file and this is the output: images/articles/1597289384.jpg

But the file is never stored in images/articles folder, I have also searched in all the folders of the project but the file was never uploaded

Could someone help me to understand why the file is being not stored?

Thank you in advance

Have a good day

0 likes
3 replies
Jecs9's avatar
Level 1

Thanks @marianomoreyra ,

Yes I did execute PHP artisan storage:link and I have tried removing the leading slash but still the same behavior, it seems to complete and the information I get in the logbook is there but the file is not in the folder or anywhere in the project

[UPDATE] I closed the IDE and opened again and now it works... I don't know what was the problem...

Sinnbeck's avatar

You might have forgotten to save a file, and your IDE did so automatically when restarted :)

Please or to participate in this conversation.