【发布时间】:2014-04-16 21:13:11
【问题描述】:
我在我的网站中使用 Redactor,该网站基于 Code canyon 中的 Tickets by Dalegroup 模块。我希望能够从剪贴板复制和粘贴图像(基本上是从 word 复制文档并将其与图像原封不动地粘贴)Redactor Settings Page 我试图让它发挥作用,但我无法让它继续下去。我尝试创建自己的文件上传脚本:
<?php
$dir = '/knowledge/files/';
$contentType = $_POST['contentType'];
$data = base64_decode($_POST['data']);
$filename = md5(date('YYHis')).'.png';
$file = $dir.$filename;
file_put_contents($file, $data);
echo json_encode(array('filelink' => '/tmp/'.$filename));
?>
上面这个好像不行,我也启用了他们网站上的功能:
This setting allows to paste images from clipboard and upload them to the server. It works in latest Chrome, Firefox and Opera (Webkit).
Default setting is true, to turn off, set clipboardUpload: false.
To perform pasted images uploads, set the following:
$('#redactor').redactor({
clipboardUploadUrl: '/your_clipboard_upload_script/'
});
现在我唯一没有尝试过的是那里的代码的底部,因为编辑器文件包含一个包含所有启用选项的部分,所以我认为我不需要它。怎么可能让它工作?
谢谢。
更新:
好的,通过在 redactor.js 中启用和设置一些变量,我能够让复制和粘贴为 redactor 工作:
dragUpload: true, // false
imageTabLink: true,
imageUpload: '/user/files/', // url
imageUploadParam: 'file', // input name
imageResizable: true,
fileUpload: '/user/files/', // url
fileUploadParam: 'file', // input name
clipboardUpload: true, // or false
clipboardUploadUrl: '/user/files/', // url
然后在我的 html_header.php 票证文件中,我从第 69 行开始在 $('.wysiwyg_enabled').redactor 代码中添加了以下内容:
clipboardUploadUrl: '/user/files/fileupload.php',
fileUpload: '/user/files/fileupload.php'
最后添加了我的fileupload.php:
<?php
// files storage folder
$dir = '/user/files/';
$_FILES['file']['type'] = strtolower($_FILES['file']['type']);
if ($_FILES['file']['type'] == 'image/png'
|| $_FILES['file']['type'] == 'image/jpg'
|| $_FILES['file']['type'] == 'image/gif'
|| $_FILES['file']['type'] == 'image/jpeg'
|| $_FILES['file']['type'] == 'image/pjpeg')
{
// setting file's mysterious name
$file = $dir.md5(date('YmdHis')).'.jpg';
// copying
move_uploaded_file($_FILES['file']['tmp_name'], $file);
// displaying file
$array = array(
'filelink' => '/user/images/'.$file
);
echo stripslashes(json_encode($array));
}
?>
似乎一切正常,但我在 chrome 中收到错误:Uncaught SyntaxError: Unexpected end of input。它不在我的代码中,而是在 Jquery 本身中。由于错误,复制和粘贴在 Mozilla 中效果很好,而不是 IE,有时在 Chrome 中效果很好。
【问题讨论】: