“Blueimp jQuery File Upload” rename files

后端 未结 7 2030
挽巷
挽巷 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条回答
  •  迷失自我
    2021-02-19 15:54

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

    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);
    
                    //...
    }
    

提交回复
热议问题