Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/409.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图像上载不工作_Javascript_Php_Ajax_Content Management System_Summernote - Fatal编程技术网

Javascript Summernote图像上载不工作

Javascript Summernote图像上载不工作,javascript,php,ajax,content-management-system,summernote,Javascript,Php,Ajax,Content Management System,Summernote,我在summernote图像上传方面遇到问题 我的脚本看起来像这样: <script> $(document).ready(function() { var IMAGE_PATH = 'http://localhost/dist/images/'; $('.summernote').summernote({ height: 300, callbacks : { onImageUpload: function(image) {

我在summernote图像上传方面遇到问题

我的脚本看起来像这样:

<script>
 $(document).ready(function() {

var IMAGE_PATH = 'http://localhost/dist/images/';

$('.summernote').summernote({
    height: 300,
    callbacks : {
        onImageUpload: function(image) {
            uploadImage(image[0]);
        }
    }
});

function uploadImage(image) {
    var data = new FormData();
    data.append("image",image);
    $.ajax ({
        data: data,
        type: "POST",
        url: "uploader.php",
        cache: false,
        contentType: false,
        processData: false,
        success: function(url) {
            var image = IMAGE_PATH + url;
            $('.summernote').summernote('insertImage', image);
            },
            error: function(data) {
                console.log(data);
                }
        });
    }

});
</script>
<?php
## This file is being used by 
##summer note for image upload call back.

include_once("classes/class.connection.php");
include_once("classes/class.config.php");
include_once("classes/class.query.php");
include_once("classes/class.common.php");

$comObj = new common;


if(empty($_FILES['file'])){ exit(); }

$errorImgFile = $comObj->sObj->config['site_url']."/admin/img-uploads/img_upload_error.png";

    if (getimagesize($_FILES["file"]["tmp_name"]) !== false)
    {   
        #Rename
        $randomName = $comObj->randomkeys(20);

        $thumbExt = $comObj->getExtension($_FILES['file']['name']);

        $newName = $randomName.".".$thumbExt;

        $destinationFilePath = './img-uploads/'.$newName;

        $rawlocation = '/img-uploads/'.$newName;



        if(!move_uploaded_file($_FILES['file']['tmp_name'], $destinationFilePath)){
            echo $errorImgFile;
        }
        else{
            echo $comObj->sObj->config['site_url']."/admin".$rawlocation;
        }


    }else{
        echo $errorImgFile;
    }
?>

$(文档).ready(函数(){
var IMAGE\u路径http://localhost/dist/images/';
$('.summernote')。summernote({
身高:300,
回调:{
onImageUpload:函数(图像){
上传图像(图像[0]);
}
}
});
函数上传图像(图像){
var data=new FormData();
数据。追加(“图像”,图像);
$.ajax({
数据:数据,
类型:“POST”,
url:“uploader.php”,
cache:false,
contentType:false,
processData:false,
成功:函数(url){
var image=image\u路径+url;
$('.summernote').summernote('insertImage',image);
},
错误:函数(数据){
控制台日志(数据);
}
});
}
});
uploader.php有以下代码:

<?php
$image = $_FILES['image']['name'];
$uploaddir = 'images/';
$uploadfile = $uploaddir . basename($image);
if( move_uploaded_file($_FILES['image']['tmp_name'],$uploadfile)) {
    echo $uploadfile;
} else {
    echo "Unable to Upload";
}
?>

图像文件已成功上载到目录“图像”

但是$('summernote').summernote('insertImage',image);不将上载的图像链接附加到编辑器


我错过了什么?是的,我尝试警告var‘image’,它具有所需的值。

您可以尝试:var image_PATH=''; 因为您的php代码:$uploadfile=>'images/xxx.jpg',html url使用两次图像,如../images/images/xxx.jpg。所以summernote图像上传不起作用! 谢谢

这是我的密码


$(文档).ready(函数(){
var IMAGE\u路径http://localhost:81/summernote-开发/示例/';
$('.summernote')。summernote({
身高:300,
回调:{
onImageUpload:函数(图像){
上传图像(图像[0]);
}
}
});
函数上传图像(图像){
var data=new FormData();
数据。追加(“图像”,图像);
$.ajax({
数据:数据,
类型:“POST”,
url:“uploader.php”,
cache:false,
contentType:false,
processData:false,
成功:函数(url){
var image=image\u路径+url;
$('.summernote').summernote('insertImage',image);
//console.log(图像);
},
错误:函数(数据){
控制台日志(数据);
}
});
}
});

好吧,我发现了一个内置了此功能的定制

我的editor-upload.php文件看起来有点像这样:

<script>
 $(document).ready(function() {

var IMAGE_PATH = 'http://localhost/dist/images/';

$('.summernote').summernote({
    height: 300,
    callbacks : {
        onImageUpload: function(image) {
            uploadImage(image[0]);
        }
    }
});

function uploadImage(image) {
    var data = new FormData();
    data.append("image",image);
    $.ajax ({
        data: data,
        type: "POST",
        url: "uploader.php",
        cache: false,
        contentType: false,
        processData: false,
        success: function(url) {
            var image = IMAGE_PATH + url;
            $('.summernote').summernote('insertImage', image);
            },
            error: function(data) {
                console.log(data);
                }
        });
    }

});
</script>
<?php
## This file is being used by 
##summer note for image upload call back.

include_once("classes/class.connection.php");
include_once("classes/class.config.php");
include_once("classes/class.query.php");
include_once("classes/class.common.php");

$comObj = new common;


if(empty($_FILES['file'])){ exit(); }

$errorImgFile = $comObj->sObj->config['site_url']."/admin/img-uploads/img_upload_error.png";

    if (getimagesize($_FILES["file"]["tmp_name"]) !== false)
    {   
        #Rename
        $randomName = $comObj->randomkeys(20);

        $thumbExt = $comObj->getExtension($_FILES['file']['name']);

        $newName = $randomName.".".$thumbExt;

        $destinationFilePath = './img-uploads/'.$newName;

        $rawlocation = '/img-uploads/'.$newName;



        if(!move_uploaded_file($_FILES['file']['tmp_name'], $destinationFilePath)){
            echo $errorImgFile;
        }
        else{
            echo $comObj->sObj->config['site_url']."/admin".$rawlocation;
        }


    }else{
        echo $errorImgFile;
    }
?>