且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

"Blueimp jQuery文件上传"重命名文件

更新时间:2023-12-04 20:40:10

旧帖子,但由于今天我正在搜索相同的内容,因此我发布了我的解决方案,希望它能对某人有所帮助.

Old post, but as I was searching the same thing today, I post my solution hoping it will help someone.

我以这种方式编辑UploadHandler.php文件:

I edited the UploadHandler.php file in this way:

        //custom function which generates a unique filename based on current time
        protected function generate_unique_filename($filename = "")
            {

                $extension = "";
                if ( $filename != "" )
                {
                    $extension = pathinfo($filename , PATHINFO_EXTENSION);

                    if ( $extension != "" )
                    {
                        $extension = "." . $extension;
                    }
                }

                return md5(date('Y-m-d H:i:s:u')) . $extension;
            }


            protected function handle_file_upload($uploaded_file, $name, $size, $type, $error,
                    $index = null, $content_range = null) {
                $file = new \stdClass();

                //MYEDIT to generate unique filename
                $file->name = $this->generate_unique_filename($name);

                //ORIGINAL LINE: $file->name = $this->get_file_name($uploaded_file, $name, $size, $type, $error, $index, $content_range);

                //...
}