“Blueimp jQuery File Upload” rename files

后端 未结 7 1927
挽巷
挽巷 2021-02-19 15:22

I\'m using the Blueimp jQuery file upload tool. I\'d like to completely rename the files as they\'re uploaded. Since photos are being added to a unique directory based on the us

7条回答
  •  Happy的楠姐
    2021-02-19 15:45

    get_file_name method is where the actual naming occurs. In order to avoid much workarounds and just hit the nail on the head, edit it as follows:

    protected function get_file_name($file_path, $name, $size, $type, $error,
            $index, $content_range) {
        $name = $this->trim_file_name($file_path, $name, $size, $type, $error,
            $index, $content_range);
        //don't return this right away; parse it to a variable
        $unique_file_name = $this->get_unique_filename(
            $file_path,
            $this->fix_file_extension($file_path, $name, $size, $type, $error,
                $index, $content_range),
            $size,
            $type,
            $error,
            $index,
            $content_range
        );
        //generate your custom name here
        $custom_name = uniqid('profilepic');
        //extract file extension
        $file_extension = pathinfo($unique_file_name, PATHINFO_EXTENSION);
        return $custom_name.'.'.$file_extension;
    }
    

提交回复
热议问题