Info Pages - wysiwyg images

Open to all! Ask other shopowners for help.
Post Reply
LeeFoster
Contributor
Posts: 263
Joined: Sun Feb 28, 2021 9:41 pm
Phoenix Version: v1.0.8.20
Has thanked: 1 time
Been thanked: 5 times

Info Pages - wysiwyg images

Post by LeeFoster »

I have modified the wysiwyg editor for info pages to add an image upload option, the default one tries to store the image in the database and it's too big.

This works fine on my 1.0.7.10 site but not on 1.0.7.15. What am I missing that's changed?

My wysiwyg hook file and the photo upload file are below.

includes/hooks/admin/info_pages/wysiwyg.php

Code: Select all

<?php
/*
  Copyright (c) 2020, G Burton

  This work is licensed under a
  Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.

  You should have received a copy of the license along with this work.
  If not, see <http://creativecommons.org/licenses/by-nc-nd/4.0/>.
*/

class hook_admin_info_pages_wysiwyg {

  function listen_injectSiteStart() {
    $editor_scripts = <<<ES
<link href="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote-bs4.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote-bs4.min.js"></script>
ES;
    
    return $editor_scripts;
  }
  
  function listen_injectBodyEnd() {
    $editor_script = <<<ES
<script>
$(document).ready(function() {
  $('.editor').summernote({
    height: 300,
    toolbar: [
      ['style', ['bold', 'italic', 'underline', 'strikethrough', 'clear']],
      ['fontsize', ['fontname', 'fontsize', 'style']],
      ['color', ['color']],
      ['para', ['ul', 'ol', 'paragraph']],
	  ['insert', ['link', 'picture', 'video']],
      ['height', ['height']],
      ['table', ['table']],
      ['util', ['undo', 'redo']],
      ['view', ['fullscreen', 'codeview', 'help']],
    ],
	callbacks: {
    onImageUpload: function(files) {
        for(let i=0; i < files.length; i++) {
            $.upload(files[i]);
        }
    }
}
	  });
$.upload = function (file) {
    let out = new FormData();
    out.append('file', file, file.name);

    $.ajax({
        method: 'POST',
        url: 'ext/imageupload/imageupload.php',
        contentType: false,
        cache: false,
        processData: false,
        data: out,
        success: function (img) {
            $('.editor').summernote('insertImage', img);
        },
        error: function (jqXHR, textStatus, errorThrown) {
            console.error(textStatus + " " + errorThrown);
        }
    });
};
});

</script>

ES;
    
    return $editor_script;
  }
  
  
  



}

admin/ext/imageupload/imageupload.php

Code: Select all

<?php
if ($_FILES['file']['name']) {if (!$_FILES['file']['error']){
$name = md5(rand(100, 200));
$ext = explode('.', $_FILES['file']['name']);
$filename = $name . '.' . $ext[1];
$destination = $_SERVER['DOCUMENT_ROOT'] . '/images/infopages/' . $filename; //change this directory
$location = $_FILES["file"]["tmp_name"];
move_uploaded_file($location, $destination);
echo '//witchwindgames.com/images/infopages/' . $filename;
}else{
echo  $message = 'Ooops!  Your upload triggered the following error:  '.$_FILES['file']['error'];
}
} ?>


Join The Code Co-op to get access to your library in the Code Co-op Forum
User avatar
burt
Core Team
Posts: 4547
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 412 times

Re: Info Pages - wysiwyg images

Post by burt »

Make sure you have relevant permissions to save the file into the folder it is trying to save to.
Look at hosting account error_log, which might shine a light on the problem.
I am not here to build for you.
I am here to build with you. Let's help each other.
LeeFoster
Contributor
Posts: 263
Joined: Sun Feb 28, 2021 9:41 pm
Phoenix Version: v1.0.8.20
Has thanked: 1 time
Been thanked: 5 times

Re: Info Pages - wysiwyg images

Post by LeeFoster »

I've just checked and it is uploading the file, it's not putting it into the text area though.
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: Info Pages - wysiwyg images

Post by ecartz »

LeeFoster wrote: Thu Mar 11, 2021 7:26 pm admin/ext/imageupload/imageupload.php
Some hosts have trouble with handlers in subdirectories of admin. Perhaps your 1.0.7.10 and 1.0.7.15 sites are configured differently? I mean at the hosting level.
LeeFoster
Contributor
Posts: 263
Joined: Sun Feb 28, 2021 9:41 pm
Phoenix Version: v1.0.8.20
Has thanked: 1 time
Been thanked: 5 times

Re: Info Pages - wysiwyg images

Post by LeeFoster »

ecartz wrote: Fri Mar 12, 2021 12:05 am
LeeFoster wrote: Thu Mar 11, 2021 7:26 pm admin/ext/imageupload/imageupload.php
Some hosts have trouble with handlers in subdirectories of admin. Perhaps your 1.0.7.10 and 1.0.7.15 sites are configured differently? I mean at the hosting level.
Both are hosted locally for testing, the 1.0.7.10 store works as it should. The 1.0.7.15 uploads the file but doesn't insert it in the text editor.

I'm guessing the issue is with the callback. I'm going to look into it more today.


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply