开发者

Add random characters to end of file path

I have this

$resizeObj -> saveImage('images/'.$pic, 90);

and I want to append random characters at the end of file name in order to prevent duplicate names 开发者_StackOverflow社区using somethign like this:

    function genRandomString() {
    $length = 10;
    $characters = ’0123456789abcdefghijklmnopqrstuvwxyz’;
    $string = ”;    

    for ($p = 0; $p < $length; $p++) {
        $string .= $characters[mt_rand(0, strlen($characters))];
    }

    return $string;
}

Whta is the best way to incorporate this into $resizeObj


$pathinfo = pathinfo($pic);
$pic = sprintf("%s%s.%s", $pathinfo['basename'], getRandomString(), $pathinfo['extension']);
$resizeObj -> saveImage('images/'.$pic, 90);


You should not save random string. Just append a unique string (eg. uniqid()) when you present the image.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜