加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php随机图像文件名

发布时间:2020-12-13 18:24:30 所属栏目:PHP教程 来源:网络整理
导读:好吧,我使用谷歌上发现的一个片段来获取用户上传的图像并将其放在我的目录下的内容下 但我担心重复,所以我打算将图像上传为随机数 好吧,这里是我的代码,你可以理解,无论如何我想通过它 label for="file"Profile Pic:/label input type="file" name="ProfileP
好吧,我使用谷歌上发现的一个片段来获取用户上传的图像并将其放在我的目录下的内容下

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

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

<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);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读