Blueimp 更改缩略图的文件名

Blueimp change file name of a thumb

blueimp 文件上传很棒,但我想知道是否可以只更改缩略图的名称?我希望它与原始文件名不同。有没有这个选项?

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

我遇到了同样的问题,正在寻找答案。我现在是这样解决的。 您只需要在 index.php 中扩展 UploadHandler() class 并编辑所需的方法。您需要的方法称为 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;

希望对您有所帮助:)