微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐