petehouston / laravel-tinymce-simple-imageupload

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

how to change directory uploaded image? #15

Open myusufid opened 4 years ago

myusufid commented 4 years ago

hi im very love with your package, work with charm can you tell me how to change the upload directory? by default is public / img i want something else, i have tried changing the directory with my controller but in textarea tinymce its failed to load the image file

iurynadin commented 4 years ago

In the view tha contain TinyMCE includes the code below:

@include('mceImageUpload::upload_form', ['upload_url' => 'url for the method responsible for upload'])

You can copy the method uploadImage from Petehouston\Tinymce\TinymceController reponsable for upload, inside the controller defined in the 'upload_url' value above:

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

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

        return $this->mce_back($filename);
}

Add the mce_back method in the same file(controller) above:

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