【问题标题】:Can't Upload Image from froala editor无法从 froala 编辑器上传图片
【发布时间】:2014-11-20 14:58:24
【问题描述】:

我使用 XAMPP 作为服务器,而且我似乎无法像编辑器的文档向我展示的那样上传图像......这是链接: http://editor.froala.com/server-integrations/php-image-upload

我已经对此问题进行了调查,通常他们都说链接不正确,因为您需要将绝对网址放在那里,但即使这样似乎也不起作用。

代码如下: JS

 $(document).ready(function(){

    $('textarea').editable({inlineMode: false, height:200, imageUploadURL: 'upload_image.php',  imageErrorCallback: function (data) {
     // Bad link.
    console.log(data);
}
});
  });

上传图片.php:

<?php
// Allowed extentions.
$allowedExts = array("gif", "jpeg", "jpg", "png");

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

// Get extension.
$extension = end($temp);

// An image check is being done in the editor but it is best to
// check that again on the server side.
// Do not use $_FILES["file"]["type"] as it can be easily forged.
$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)) {

    // Generate new random name.
    $name = sha1(microtime()) . "." . $extension;

    // Save file in the uploads folder.
    move_uploaded_file($_FILES["file"]["tmp_name"], "C:\ xampp\htdocs\Swaggy\img\ " . $name);

    // Generate response.

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

当我尝试上传图像时,他在编辑器中以 64 位格式形成一个 img 标签,然后消失。调试器向我显示文件 upload_image.php 的状态为 200,从控制台向我显示的错误是: Object {code: 4, message: "Parsing response failed"}

【问题讨论】:

    标签: javascript php json froala


    【解决方案1】:

    您的服务器中的 PHP 似乎存在问题,无法解析响应。当您尝试上传图像时,您应该使用 Firebug 检查服务器的响应。例如,finfo_file 函数仅从 PHP 5.3 开始可用。如果您的版本较旧,这很可能是问题所在。

    【讨论】:

    • 是的,我终于找到了一种方法,如何在调试器中检查来自 ajax 调用的帖子......是的,你是对的,函数未定义“致命错误:调用未定义函数 finfo_open()”问题是我的 PHP 版本是 5.5 ...我忘记了什么?顺便谢谢一堆
    • stackoverflow.com/questions/3579072/…。看来您必须在 Windows 上手动启用它。
    • 在你给我链接之前我已经解决了问题,现在它可以工作了,感谢你的关注和帮助
    猜你喜欢
    • 1970-01-01
    • 2018-01-01
    • 1970-01-01
    • 2023-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-27
    相关资源
    最近更新 更多