Javascript Froala-图像上传JSON响应
我正在使用我的网站。这个编辑器有内置的图像上传功能-图像上传工作正常,但我有问题的反应 这来自文档:Javascript Froala-图像上传JSON响应,javascript,php,json,Javascript,Php,Json,我正在使用我的网站。这个编辑器有内置的图像上传功能-图像上传工作正常,但我有问题的反应 这来自文档: The server processes the HTTP request. The server has to process the upload request, save the image and return a hashmap containing a link to the uploaded image. The returned hashmap needs to look li
The server processes the HTTP request.
The server has to process the upload request, save the image and return a hashmap containing a link to the uploaded image. The returned hashmap needs to look like: { link: 'path_to_uploaded_file/file.png' }
这是我返回链接的功能:
public function froala_upload()
{
header('Content-type: application/json');
$folder = 'public/img/media';
$slika = $this->site->single_upload($folder, 'jpg|jpeg|png|bmp|JPG|JPEG|PNG|BMP');
$link = array("link" => $slika);
echo json_encode($link);
}
这是JS代码:
$('textarea').editable({
inlineMode: false,
imageUploadParam: "userfile",
imageUploadURL: "<?php echo base_url() ?>admin/froala_upload",
// Set the image error callback.
imageErrorCallback: function (data) {
// Bad link.
if (data.errorCode == 1) {
console.log(data);
}
// No link in upload response.
else if (data.errorCode == 2) {
console.log(data);
}
// Error during file upload.
else if (data.errorCode == 3) {
console.log(data);
}
}
});
这是我得到的回应:
{"link":"7d59d61.jpg"}
有什么问题吗
必须返回绝对图像路径:
$link = array("link" => '/img/media/'.$slika);
因为Froala会将其查找到,所以问题是无法从返回的链接加载图像。您必须确保可以从中访问图像。Froala编辑器使用从
img
标记返回的src
属性的链接。我认为你必须做一些类似的事情:
$link = array("link" => $slika . 'public/img/media');
$link = array("link" => $slika . 'public/img/media');