2

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

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

这是代码: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));
}

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

4

1 回答 1

2

It looks there is a problem with the PHP from your server and the response can't be parsed. You should check with Firebug what is the response from the server when you try to upload an image. finfo_file function for instance is available only starting with PHP 5.3. If your version is older this is the problem most probably.

于 2014-09-30T09:01:48.973 回答