更改Meioupload中的文件名

时间:2011-04-08 11:49:18

标签: php cakephp filenames image

我在使用CakePHP构建的网站上使用Meioupload,它可以正常使用多个上传字段。我现在遇到的问题是,如果A人上传了一张名为'me.jpg'的图片,然后B人上传了一张名为'me.jpg'的图片,B人就会覆盖第一次上传。

在图片上传时,Meioupload中有没有办法更改文件名?例如。将此人的用户名添加到开头,以便它看起来像'persona_me.jpg'和'personb_me.jpg'?

这是我目前的代码:

var $actsAs = array('MeioUpload' => array(
    'picture' => array(
        'dir' => 'files/device_images',
        'create_directory' => true,
        'allowed_mime' => array('image/jpeg', 'image/pjpeg', 'image/gif', 'image/png'),
        'allowed_ext' => array('.jpg', '.jpeg', '.png', '.gif'),
        'thumbsizes' => array(
               'small'  => array('width'=>100, 'height'=>100),
               'medium' => array('width'=>240, 'height'=>180),
               'large'  => array('width'=>640, 'height'=>480)
    )));

感谢您的帮助

2 个答案:

答案 0 :(得分:0)

从我记忆中使用meio上传时,图像被放置在一个名为pk的目录中,类似于/images//filename.ext

大多数情况下你想保留文件名,因为它可以用于搜索引擎优化。

答案 1 :(得分:0)

在Meio上传声明中添加此内容:'uploadName' => 'url_slug',其中url_slug是您使用表单提交的字段(实际上,它可能是架构中的字段,它都在我的应用上)。< / p>