Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/460.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何获得用户使用summernote插入的图像并将其上传到PHP中的磁盘上_Javascript_Php_Json_Summernote - Fatal编程技术网

Javascript 如何获得用户使用summernote插入的图像并将其上传到PHP中的磁盘上

Javascript 如何获得用户使用summernote插入的图像并将其上传到PHP中的磁盘上,javascript,php,json,summernote,Javascript,Php,Json,Summernote,我正在使用bootstrap中的summernote作为我的编辑器。它看起来不错,我喜欢用它。我可以得到用户插入的文本,但是,问题是当用户插入图像时,图像的src返回到二进制文本。我不想将src的整个文本保存到数据库中,而是希望将图像直接保存到我的磁盘驱动器中,复制图像名称并将其保存到数据库中 有人知道吗 谢谢 或 使用Summernote图像按钮 这是我用于cms的一个小片段 将图像上传功能集成到summernote 此代码段将使“图像上载”对话框将文件发送到磁盘。但是要处理这个问题,您必须

我正在使用bootstrap中的summernote作为我的编辑器。它看起来不错,我喜欢用它。我可以得到用户插入的文本,但是,问题是当用户插入图像时,图像的src返回到二进制文本。我不想将src的整个文本保存到数据库中,而是希望将图像直接保存到我的磁盘驱动器中,复制图像名称并将其保存到数据库中

有人知道吗

谢谢

使用Summernote图像按钮 这是我用于cms的一个小片段

将图像上传功能集成到summernote 此代码段将使“图像上载”对话框将文件发送到磁盘。但是要处理这个问题,您必须创建一个php文件来处理图像上传。 看到我的cms的这个小代码了吗

保存图像PHP文件 此php文件将文件保存到路径中。把它插入你的数据库我想你已经知道了

我希望这将有助于你或任何有同样问题的人

使用elFinder文件管理器 用于使用elFinder文件管理器。请看这个答案。


谢谢,

调用函数(
()
)。我们如何使用Summernote直接从URL将图像上载到服务器?
var weblayout = {
  data : { 
    rows : function() {
        return 1;
    } 
  }     
};

weblayout.data.rows();// call the function row()
var weblayout = {
  data : { 
    rows : function() {
        return 1;
    } 
  }     
};

var fctRow = weblayout.data.rows();// call the function row()
alert(fctRow);
$(document).ready(function() {
    $('.editor').summernote({
        height: 300,
        toolbar: [
                ['style', ['style']],
                ['style', ['bold', 'italic', 'underline', 'strikethrough', 'superscript', 'subscript', 'clear']],
                ['fontname', ['fontname']],
                ['fontsize', ['fontsize']],
                ['color', ['color']],
                ['para', ['ul', 'ol', 'paragraph']],
                ['height', ['height']],
                ['table', ['table']],
                ['insert', ['link', 'picture', 'video', 'hr', 'readmore']],
                ['genixcms', ['elfinder']],
                ['view', ['fullscreen', 'codeview']],
                ['help', ['help']]
            ],
        onImageUpload: function(files, editor, welEditable) {
                sendFile(files[0],editor,welEditable);
            }
    });

    function sendFile(file,editor,welEditable) {
      data = new FormData();
      data.append("file", file);
        $.ajax({
            url: "saveimage.php",
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            type: 'POST',
            success: function(data){
            alert(data);
              $('.editor').summernote('editor.insertImage', data);
            },
           error: function(jqXHR, textStatus, errorThrown) {
             console.log(textStatus+" "+errorThrown);
           }
        });
    }

    $(".alert").alert();
});
$url = "http://yoursite.com";
$allowed = array('png');

if(isset($_FILES['file']) && $_FILES['file']['error'] == 0){
    $extension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
    if(!in_array(strtolower($extension), $allowed)){
        echo '{"status":"error"}';
        exit;
    }
    if(move_uploaded_file($_FILES['file']['tmp_name'], GX_PATH.'/assets/images/uploads/'.$_FILES['file']['name'])){
        $tmp= '/assets/images/uploads/'.$_FILES['file']['name'];
        echo $url.'/assets/images/uploads/'.$_FILES['file']['name'];
        //echo '{"status":"success"}';
        exit;
    }
}