Froala$响应变量


Froala $response variable

我已经阅读了Froala编辑器的文档:http://editor.froala.com/server-integrations/php-image-upload

已经通读了关于堆栈溢出中相同问题的文章,但还并没有成功。$response变量存在问题,该变量将图像路径放入图像src参数中。到目前为止,froala正在将图像放在服务器上指定的文件夹中(所以脚本可以工作)。问题是froala并没有将路径放在图像源中,这样就不会添加图像。

这是我的图像上传脚本(工作非常好)

<?php
$fileName = $_FILES["image"]["name"];
$fileTmpLoc = $_FILES["image"]["tmp_name"];
$fileType = $_FILES["image"]["type"];
$fileSize = $_FILES["image"]["size"]; 
$fileErrorMsg = $_FILES["image"]["error"]; 
$kaboom = explode(".", $fileName); 
$fileExt = end($kaboom);
$fileName = time().rand().".".$fileExt;
if (!$fileTmpLoc) { 
 header('Location: ../announcments.php?aid=9');
     exit();
} else if($fileSize > 5242880) { 
    echo "ERROR: Your file was larger than 5 Megabytes in size.";
    unlink($fileTmpLoc); 
    exit();
} else if (!preg_match("/.(gif|jpg|png|JPG)$/i", $fileName) ) {
     echo "ERROR: Your image was not .gif, .jpg, or .png.";
     unlink($fileTmpLoc); 
     exit();
} else if ($fileErrorMsg == 1) { 
    echo "ERROR: An error occured while processing the file. Try again.";
    exit();
}
$moveResult = move_uploaded_file($fileTmpLoc, "../uploads/contentimg/$fileName");
if ($moveResult != true) {
    echo "ERROR: File not uploaded. Try again.";
    unlink($fileTmpLoc); 
    //This bit has been taken as example from froala website. 
    // Generate response.
        $response = new StdClass;
        $response->link = "/uploads/contentimg/" . $fileName;
        echo stripslashes(json_encode($response));
        //example from froala ends
    exit();
}

所以这肯定是错误的,因为其他一切都在起作用:

// Generate response.
            $response = new StdClass;
            $response->link = "/uploads/contentimg/" . $fileName;
            echo stripslashes(json_encode($response));

请帮忙。

保存图像时,会发出POST请求。响应将是这样的:{link: '/uploads/contentimg/file_name.jpg'}。在您的情况下,您必须确保响应链接可以作为绝对路径在浏览器中访问。如果你在http://example.com/my/long/path,将在上访问图像http://example.com/uploads/contentimg/file_name.jpg.