php上传文件并将其名称添加到数据库的一列中,但如何更改名称autoincrement


php upload file and adding it name to a column of database but how to change the name autoincrement

表格:

id, name, filename
1   ab    temp1.pdf
2   cd    temp2.pdf
...................

类别:

public function attach_file($file){
  if(!$file || empty($file){
     $this->errors[] = "No file";
  } else {
      $this-temp_path = $file['tmp_name'];
      $this->filename = basename($file['name']);
}

这将上传我的文件,但在上($this->filename=basename($file['name'](如何设置自动递增的名称,如名称+1,它应该知道最后一个记录文件名是temp,new将是temp1,new将为temp3这应该代替我的(basename($file['name'](

关于

我是这样发现的:

$rand_value = rand();
$this->filename = basename($rand_value."_".$file['name']);