无法使用froala

时间:2016-05-18 10:29:19

标签: php codeigniter froala

我正在使用codeigniter在网站上工作,我尝试使用Froala编辑器在textarea中上传图片。在我尝试将图像文件上传到我的本地文件夹而不是默认的http://i.froala.com/upload

之前,它一切正常

这是我的html文件:

<textarea id="my_editor" name="my_editor" class="editor">
</textarea>
<script>
  $(function() {
    $('.editor').froalaEditor({
      imageUploadURL: "test/froala_upload",
    })
  });
</script>

这是froala_upload控制器文件中的Test函数:

function froala_upload() {

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

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

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

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

    // Save file in the uploads folder.
    move_uploaded_file($_FILES["file"]["tmp_name"], getcwd(). "/assets/review/" . $name);

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

我故意省略了finfo的图像检查,var dependsOn= { qTableIdent: { //External object key mapping( object key : external key) 'RHID': 'RHID', 'CD_AGREGADO': 'NOME' } }, var tableCols= [ { "targets": 1, "title": 'RHID', "label": 'RHID', "data": 'RHID', "name": 'RHID', "width": "5%", "filter": true, "defaultContent": "", "visible":false, "type": 'hidden', //ADD this to properties attr: { 'name': 'rhid' }, },..... ] 用于大多数关于Froala图片上传的文档,因为有些人说这可能是问题 - 但我还是无法上传图像文件。并且错误消息非常有用:&#34;出了点问题。请再试一次&#34;

我花了好几个小时在这件事上摸不着头脑。在广阔的互联网世界中,对于这个问题,实际上没有完整的代码解决方案,所以我无法找出我做错的事情。任何人都可以帮我这个吗?

3 个答案:

答案 0 :(得分:2)

根据他们的文档,您应该使用此代码

<script>
  $(function() {
    $('.selector').froalaEditor({
      // Set the image upload URL.
      imageUploadURL: '/your_upload_image_script.php',

      imageUploadParams: {
        id: 'my_editor'
      }
    })
  });
</script>

接下来你必须创建一个名为your_upload_image_script.php的文件,它应该像

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

    // 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(strtolower($extension), $allowedExts)) {
        // Generate new random name.
        $name = sha1(microtime()) . "." . $extension;

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

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

答案 1 :(得分:0)

它可能缺少extension值。

尝试以下

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

$extension = end($temp);
if ($extension == "") {
    list($dummy, $extenstion) = explode("/", $mime);
}

答案 2 :(得分:0)

F    MACRO  arg1
if ~ arg eq
mov ax, arg1
add ax,ax
add ax, 5
end if
ENDM