drfu29983 2013-08-07 10:43
浏览 26
已采纳

如何在redactor编辑器中使用图像文件名

while uploading an image in redactor editor, it itself rename the image file name with md5 encryption of current date and time. But i want to use the image file name.
You can see a live demo here: http://imperavi.com/redactor/
So, if a image file name is bird.jpg then i want to keep it as bird.jpg after upload it in editor, instead of something like this e1cbe0be9c301f7f73f3271a86508db3.jpg
How Images upload Works:
redactor.js file or by setting this option on load, for example:

<script type="text/javascript">
$(document).ready(
function()
{
    $('#redactor_content').redactor({
        imageUpload: '/modules/upload.php'
    });
}
);
</script>

Let's assume that upload.php file will handle images. Its code may look like this:

<?php

// files storage folder
$dir = '/home/web/sitecom/redactor/images/';

$_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' => '/images/'.$file
);

echo stripslashes(json_encode($array));
}

?>

JSON example:

{ "filelink": "/images/img.jpg" }

so how to keep the $file to be the image name instead of the md5 data?

  • 写回答

1条回答 默认 最新

  • doujue1246 2013-08-07 10:52
    关注

    Change in upload.php

    $file = $dir.md5(date('YmdHis')).'.jpg';

    to

    $file = $_FILES['file']['name'];

    you get the file name in $file

    for more reference you can check docs at http://imperavi.com/redactor/docs/files/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器