1

我在使用 php 上传图像时设置 froala 编辑器时遇到问题。

我已阅读 Froala 编辑器的文档

这是我的js函数:

$(function() {
    $('#edit-ru').editable({
        inlineMode: false,
        imageUploadURL: 'upload_image.php'
    }).on('editable.imageError', function (e, editor, error) {
            // Custom error message returned from the server.
            if (error.code == 0) { alert("error"); }

            // Bad link.
            else if (error.code == 1) { alert("bad link"); }

            // No link in upload response.
            else if (error.code == 2) { alert("no link"); }

            // Error during image upload.
            else if (error.code == 3) { alert("during image"); }

            // Parsing response failed.
            else if (error.code == 4) { alert("parsing error"); }

            // Image too large.
            else if (error.code == 5) { alert("large image"); }

            // Invalid image type.
            else if (error.code == 6) { alert("invalid image"); }

            // Image can be uploaded only to same domain in IE 8 and IE 9.
            else if (error.code == 7) { alert("ie8 error"); }
        }).imageInserted (e, editor, img, response)
});

和我的 upload_image.php 文件

$allowedExts = array("gif", "jpeg", "jpg", "png");

$temp = explode(".", $_FILES["file"]["name"]);

$extension = end($temp);

$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $_FILES["file"]["tmp_name"]);

if ((($mime == "image/gif")
|| ($mime == "image/jpeg")
|| ($mime == "image/pjpeg")
|| ($mime == "image/x-png")
|| ($mime == "image/png"))
&& in_array($extension, $allowedExts)) {

$name = sha1(microtime()) . "." . $extension;

move_uploaded_file($_FILES["file"]["tmp_name"], getcwd() . "uploads/" . $name);

$response = new StdClass;
$response->link = "uploads/" . $name;
echo stripslashes(json_encode($response));}

请帮我设置一下!我尝试了任何方法,但 id 无法正常工作!可能是什么原因?

提前致谢!

4

1 回答 1

1

替换uploads//uploads/

于 2016-02-01T22:47:24.047 回答