Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery file upload - how to overwrite file NOT rename

I am struggling to update the Jquery file upload plugin so when you upload a file it just overwrites an existing file with the same name instead of renaming it with an upcount.

I have applied the change covered in this link: https://github.com/blueimp/jQuery-File-Upload/issues/1965

but I can't seem overwrite this plugin to get this working?

there's an existing open question not yet answered here: jQuery File Upload by bluimp, how to replace instead of renaming

any guidance on this would be much appreciated.

like image 674
user1746582 Avatar asked Feb 09 '13 10:02

user1746582


2 Answers

If you using UploadHandler.php that is exists in the wiki it's simple. In the get_file_name method you should replace this line:

    return $this -> get_unique_filename($this -> trim_file_name($name, $type, $index, $content_range), $type, $index, $content_range);

with this:

 return $this -> trim_file_name($name, $type, $index, $content_range);
like image 135
MKoosej Avatar answered Sep 27 '22 18:09

MKoosej


2016 UPDATE to MKoosej's fix! In UploadHandler.php → protected function get_file_name ... replace

return $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
    );

with

return $this -> trim_file_name($file_path, $name, $size, $type, $error, $index, $content_range);
like image 32
Andreikin Yura Avatar answered Sep 27 '22 18:09

Andreikin Yura