How to increment filename in php to prevent duplicates

前端 未结 4 1619
忘了有多久
忘了有多久 2020-12-10 17:02

In many situations, we need to make the filename different on the server when creating them to prevent duplication. And the most common answer to that seems to be, append th

4条回答
  •  天命终不由人
    2020-12-10 17:23

    All these answers seem overkill:

    $k = 0;
    while(!$result){
        if(!file_exists("file[$k].ext"))
            $result = "file[$k].ext";
        $k++;
    }
    makefile($result);
    

提交回复
热议问题