【问题标题】:redactor copy and paste images from clipboard编辑器从剪贴板复制和粘贴图像
【发布时间】: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 中效果很好。

【问题讨论】:

    标签: php redactor


    【解决方案1】:

    这可能无济于事 - 我目前正在尝试做同样的事情 - 但这里有一个编辑器包工作: https://github.com/kraksoft/RedactorBundle 我实际上正在使用它(我也分叉了这个项目,但没有带来任何新东西),并且图像上传工作,我认为我离使剪贴板上传工作不远,保持更新捆绑!

    【讨论】:

    • 优秀。在昨天玩过它之后,我能够让复制粘贴工作,但它现在将它存储在数据库中的 md5 哈希中。问题是文章的视图没有读取 md5。
    • 哦,你成功了吗?你是如何让复制粘贴工作的@user3542866?对于 md5 哈希,您应该尝试编辑 RedactorService.php 文件并使用 $newfilename
    • 我尝试了同样的方法,但当我复制和粘贴图像时,redactor 仍然不执行任何操作。所以你对任何上传都使用相同的上传脚本?
    • 是的,它似乎工作正常,除此之外查看器不显示任何内容。如果你愿意,我可以为我的网站创建一个登录名来查看。
    • 我使用的是 symfony 框架,所以我不能使用独立的 php 文件,这就是为什么我尝试使用我在答案中链接的包,但 clipboardUpload 不起作用......跨度>
    猜你喜欢
    • 2013-07-08
    • 1970-01-01
    • 1970-01-01
    • 2013-10-11
    • 2010-10-04
    • 1970-01-01
    • 1970-01-01
    • 2018-11-24
    相关资源
    最近更新 更多