Froala编辑器上传

时间:2017-05-02 10:17:05

标签: php froala

您好我正在使用froala编辑器,我可以设法保存我的数据库中的内容现在我只是想将图像上传到我的服务器,但我没有运气到目前为止我唯一的输出是“出了问题,再试一次“这是我的代码。

<body>
  <div id="editor"></div>
</body>

<script>


 $(function() {
    $('#editor').froalaEditor({
      // Set the image upload URL.
      imageUploadURL: 'save.php',

      imageUploadParams: {
        id: 'my_editor'
      }
    })
  });


</script>

在我的save.php上

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

    // Get filename.
    $temp = explode(".", $_FILES["my_editor"]["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["my_editor"]["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["my_editor"]["tmp_name"], getcwd() . "/upload_image/" . $name);

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

我正在尝试将上传的文件保存到我的服务器内名为upload_image的文件夹中。

0 个答案:

没有答案