Witam,
Używam na swojej stronie skryptu uploadu BlueImp jQuery file Update:
https://github.com/blueimp/jQuery-File-Upload
I mam pytanie zastanawiam się jak moża zmienić nazwę uploadowanego pliku, poprzez jakąś funkcję hashowania?
W kodzie BlueImp znalazłem taki kod:
protected function trim_file_name($file_path, $name, $size, $type, $error, $index, $content_range) { // Remove path information and dots around the filename, to prevent uploading // into different directories or replacing hidden system files. // Also remove control characters and spaces (\x00..\x20) around the filename: $name = trim($this->basename(stripslashes($name)), ".\x00..\x20"); // Use a timestamp for empty filenames: if (!$name) { $name = str_replace('.', '-', microtime(true)); } return $name; }
I zastanawiam się jak go mogę użyć w swoim skrypcie do zmiany nazwy, a raczej jej zahashowania.
Jak dotąd mój kod wygląda tak:
$(function () { 'use strict'; // Change this to the location of your server-side upload handler: var url = 'server/php/'; $('#fileupload').fileupload({ url: url, dataType: 'json', done: function (e, data) { $.each(data.result.files, function (index, file) { $('<input>').attr({ type: 'text', name: 'text', value: file.url }).appendTo('#files'); }); }, progressall: function (e, data) { var progress = parseInt(data.loaded / data.total * 100, 10); $('#progress').val( progress ); } }).prop('disabled', !$.support.fileInput) .parent().addClass($.support.fileInput ? undefined : 'disabled'); }); $('#fileupload').bind('fileuploadsubmit', function (e, data) { $("#progress").fadeIn(); $.each(data.files, function (index, file) { $('<p></p>').text(file.name).appendTo('#files'); }); })