almokhtar_br's avatar

help !!! how i can keep the image uploaded in edit page

   <div class="row">
                                <div class="col-3">
                                    <div class="c-field">
                                        <label for="">Image : </label>
                                        <input type="file" name="imagepath" value="{{ $post->image_path }}">
                                    </div>
                                </div>
                                <div class="col-9">
                                    <div class="uk-margin uk-grid-small uk-child-width-auto uk-grid">
                                        <label for="">Tags : </label>
                                    @foreach($tags as $tag)
                                    <label><input
                                            @foreach($post->tags as $t)
                                                    @if($tag->id == $t->id)
                                                    checked
                                                     @endif
                                             @endforeach
                                            class="uk-checkbox" type="checkbox" name="tag[]" value="{{ $tag->id }}"> {{ $tag->tag }} </label>
                                    @endforeach
                                    </div>
                                </div>
                            </div>
0 likes
6 replies
Cronix's avatar

You can't repopulate <input type="file">. It's just not allowed in the HTML spec, otherwise you could inject all sorts of malicious files into the users browser. The file must be chosen by the user, each time.

1 like
Cronix's avatar

Well that will allow them to select image types by default when the click on the file button, but you still cannot set it's value. No matter what you try. HTML won't allow it. You cannot do value="whatever" on file inputs.

Note: The value attribute cannot be used with <input type="file">.

https://www.w3schools.com/tags/att_input_value.asp

1 like
Helmchen's avatar
Helmchen
Best Answer
Level 15

You probably want to populate an hidden input and use this instead for future requests .. so check for either the real file input or the hidden input.

This only assumes that you temporarily save the file somewhere after the upload (if something goes wrong) so that you can reference it during the next request.

session should also work

1 like
jlrdw's avatar

In edit page just show file name for image. If it needs edit put in the code (like change image) via a button where the images /s can be dwelt with separate from the other fields. You may want to add in the code to delete image from disk at the same time if no longer needed.

The changing of image could be a regular popup or modal. Or even a package that specializes in dealing with images.

Once the new image is dwelt with then the name of the new image can be retrieved from popup or modal prior to the window.close.

Just a thought.

1 like

Please or to participate in this conversation.