S
S
shane892015-11-23 21:20:44
PHP
shane89, 2015-11-23 21:20:44

How to change file name to user id?

Good evening. Such a problem, you need to change the file name to the name of the user id. Uploading via ajax upload. How to solve the problem?
How to pass namefile variable?

var button = $('span.upload-file'), interval;
        var namefile = $('.main-user-id').val();

        $.ajax_upload(button, {
            action : '/upload.php',
            name : 'round',
            onSubmit: function(file, ext) {
              	this.disable();
                $('span.upload-file').html('загружаем <i class="fa fa-spinner"></i>');
            },
            onComplete: function(file, response) {
              	this.enable();
              	alert(namefile);
              	$('span.upload-file').html('залить на сервер <i class="fa fa-upload">');
            }
        });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2015-11-23
@R0dger

Form the file manually.. i.e. name ... you will find out the extension .. and the name manually .. sometimes I format it like this

$filename = pathinfo($_FILES['file']['name'], PATHINFO_FILENAME);
      $ext = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
      $uid = uniqid();
      $fn = Utils::translitUrl($filename).'-'.$uid.'.'.$ext;
      $destination = IMAGE_COLLECTION. '/' . $fn;
      move_uploaded_file( $_FILES['file']['tmp_name'] , $destination );

You can use at least id .. at least something else))) It all depends on you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question