Сгенерировать уникальное имя файла с помощью PHP?

#php

#php

Вопрос:

Я использую php-скрипт для загрузки изображений в каталог. Я пытаюсь выяснить, почему скрипт не присваивает изображениям уникальное имя файла перед сохранением их в каталоге. Я загружаю только одно изображение за раз, и я включил сюда соответствующую часть php, которая, как я думал, создаст уникальные имена файлов. Кто-нибудь может сказать мне, почему изображения не получают уникальных имен?

 //proportionally resize image
    private function resize_it(){
        if($this->file_count > 0){
            if(!is_array($this->file_data['name'])){
                throw new Exception('HTML file input field must be in array format!');
            }
            for ($x = 0; $x < $this->file_count; $x  ){

                if ($this->file_data['error'][$x] > 0) { 
                    $this->upload_error_no = $this->file_data['error'][$x];
                    throw new Exception($this->get_upload_error()); 
                }   

                if(is_uploaded_file($this->file_data['tmp_name'][$x])){

                    $this->curr_tmp_name = $this->file_data['tmp_name'][$x];
                    $this->get_image_info();

                    //create unique file name
                    if($this->random_file_name){ 
                        $this->new_file_name = uniqid().$this->get_extension();
                        $this->unique_rnd_name[$x] = $this->new_file_name;
                    }else{
                        $this->new_file_name = $this->file_data['name'][$x];
                    }

                    $this->curr_tmp_name = $this->file_data['tmp_name'][$x];
                    $this->image_res = $this->get_image_resource();
                    $this->save_dir = $this->destination_dir;
  

Комментарии:

1. Может $this->random_file_name быть, есть false ?

2. Да! Это было все. Спасибо.