php随机图像文件名

好吧,我使用谷歌上发现的一个片段来获取用户上传的图像并将其放在我的目录下的内容

但我担心重复,所以我打算将图像上传随机

好吧,这里是我的代码,你可以理解,无论如何我想通过它

<label for="file">Profile Pic:</label> <input type="file" name="ProfilePic" id="ProfilePic" /><br />

<input type="submit" name="submit" value="Submit" />

$ProfilePicName = $_FILES["ProfilePic"]["name"];
$ProfilePicType = $_FILES["ProfilePic"]["type"];
$ProfilePicSize = $_FILES["ProfilePic"]["size"];
$ProfilePicTemp = $_FILES["ProfilePic"]["tmp_name"];
$ProfilePicError = $_FILES["ProfilePic"]["error"];

$RandomAccountNumber = mt_rand(1,99999);  
echo $RandomAccountNumber; 
move_uploaded_file($ProfilePicTemp,"Content/".$RandomAccountNumber.$ProfilePicType);

然后基本上所有这一切后,我试着把它随机数放在我的数据库

有人给了我一个新的片段,看起来它会做我想要的但现在文件不是一直到我的目录

$RandomAccountNumber = uniqid();
echo $RandomAccountNumber;

move_uploaded_file($ProfilePicName,"Content/".$RandomAccountNumber);
尝试使用PHP uniqid方法生成您需要的唯一ID

http://php.net/manual/en/function.uniqid.php

$RandomAccountNumber = uniqid();
move_uploaded_file($ProfilePicTemp,"Content/" . $RandomAccountNumber);

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...