Blueimp更改拇指的文件名

时间:2016-05-13 12:45:26

标签: blueimp

blueimp fileuploader是greate,但我想知道是否可以只更改拇指的名称?我希望它与原始文件名不同。有这样的选择吗?

$options = array(
  'thumbnail' => array( 
     'upload_dir' => '../thumb/',  
     'upload_url' => 'thumb/',
     'thumbnail_name' => $thumbName 
);
$upload_handler = new UploadHandler($options);

1 个答案:

答案 0 :(得分:1)

我有同样的问题,正在寻找答案。我现在这样解决了。 您只需要在index.php中扩展 UploadHandler()类,然后编辑想要的方法。您需要的方法称为 get_scaled_image_file_paths()。在那里,您可以在if条件中更改文件路径和名称。这里是index.php的示例:

require('UploadHandler.php');

class CustomUploadHandler extends UploadHandler {
    protected function get_scaled_image_file_paths($file_name, $version) {
        $file_path = $this->get_upload_path($file_name);
        if (!empty($version)) {
            $version_dir = $this->get_upload_path(null, $version);
            if (!is_dir($version_dir)) {
                mkdir($version_dir, $this->options['mkdir_mode'], true);
            }

            switch (strtolower(pathinfo($file_path, PATHINFO_EXTENSION))) {
                case 'jpeg':
                case 'jpg':
                    $file_type = 'jpg';
                    break;
                case 'png':
                    $file_type = 'png';
                    break;
                case 'gif':
                    $file_type = 'gif';
                    break;
            }
            $file_name = 'custom_prefix_'.$version.'.'.$file_type;

            $new_file_path = $version_dir.'/'.$file_name;
        } else {
            $new_file_path = $file_path;
        }
        return array($file_path, $new_file_path);
    }
}

$options = array(
    'image_versions' => array(
        '' => array(
            // Automatically rotate images based on EXIF meta data:
            'auto_orient' => true
        ),
        '100' => array(
            'upload_dir' => $_SERVER['DOCUMENT_ROOT'].'/uploads/thumbs/',
            'upload_url' => 'http://my.url/uploads/thumbs/',
            'max_width' => 100,
            'max_height' => 100
        ),
        '500' => array(
            'upload_dir' => $_SERVER['DOCUMENT_ROOT'].'/uploads/thumbs/',
            'upload_url' => 'http://my.url/uploads/thumbs/',
            'max_width' => 500,
            'max_height' => 500
        ),
    )
);

$upload_handler = new CustomUploadHandler($options);

如果你想使用$ options-array,那么有一个内置方法

$options = $this->options;

我希望这会有所帮助:)