无法从froala编辑器上传图像

时间:2014-09-25 18:11:06

标签: javascript php json froala

我正在使用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);
}
});
  });

upload_image.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));
}

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

1 个答案:

答案 0 :(得分:1)

看起来您的服务器上的PHP存在问题,无法解析响应。您应该使用Firebug查看尝试上传图像时服务器的响应。例如,finfo_file函数仅从PHP 5.3开始可用。如果您的版本较旧,则最有可能出现此问题。