petehouston / laravel-tinymce-simple-imageupload

Simple image upload for TinyMCE in Laravel.
69 stars 25 forks source link

Unable to view the image #5

Closed SandeepBanerjee closed 5 years ago

SandeepBanerjee commented 7 years ago

Hi i successfully add the images (Thank you very much for this), however i am unable to show the image it will look like this: sample

the94air commented 7 years ago

I had the same problem. but I changed the file path in the @include('mceImageUpload::upload_form') view and it now works perfectly.

a-ssassi-n commented 7 years ago

@the94air I am facing the same issue, I am unable to find any specified file path in upload_form view. Could you please let me know what exactly did you change??

Update: I fixed the issue doing the following:

Changed mce_back function in the helper.php to:

function mce_back($filename)
    {
        return ("
            <script>
            top.$('.mce-btn.mce-open').parent().find('.mce-textbox').val('$filename').closest('.mce-window').find('.mce-primary').click();
            </script>
        ");
    }

And

Changed the uploadImage method to this:

public function uploadImage(Request $request)
    {
        $image = $request->file('image');

        $filename = 'image_'.time().'_'.$image->hashName();
        $image = $image->move(public_path('img/uploads'), $filename);

        $filepath = url('/img/uploads') .'/' .$filename;
        return mce_back($filepath);
    }

Screenshot: capture

the94air commented 7 years ago

@a-ssassi-n That is exactly what I did. It looks simple but completely powerful. It is so awesome.

rambo666 commented 6 years ago

@a-ssassi-n and everybody else, I would not recomend you to edit any files residing in vendor as it will get updated with every composer updates. Therefore, You must create a new helper function somewhere in app directory and register in the AppServiceProvider.php. This way you can use your own version of helper service and you do not have to keep changing the vendor files. The above solution by @a-ssassi-n is very effective but only for short period of time.

the94air commented 6 years ago

Thanks, @rambo666 I forgot to mention that in my comment. I have a helper file in my laravel app and I didn't edit the package helper file.