JQuery BlueImp how to change file name before downloading?

Is it possible to change the file name of the uploaded file via jquery blueimp?

+5
source share
3 answers

require('UploadHandler.php'); class CustomUploadHandler extends UploadHandler { protected function trim_file_name($file_path, $name, $size, $type, $error, $index, $content_range) { $name = 'First_' . microtime(true); $name = str_replace('.', '', $name); return $name; } } $upload_handler = new CustomUploadHandler(); 

In your custom file, index.php initializes this function UploadHandler.php

+8
source

This can only be achieved by replacing the trim_file_name () function as follows in the UploadHandler.php file.

 protected function trim_file_name(VARIABLES) { $name = uniqid(); return $name; } 

and that's all

+3
source

This solution was published by the user 'lethal.industry' here . You must paste this code inside the UploadHandler class in the UploadHandler.php file

  //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('Ymd H:i:s:u')) . $extension; } 

You can change the file name as you like, change the last line of "return ..."

Then you search for the handle_file_upload function in UploadHandler.php and replace this line

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

for this line

 $file->name = $this->generate_unique_filename($name); 
-1
source

Source: https://habr.com/ru/post/1206138/


All Articles