好的,我在使用谷歌上找到的代码片段,用于获取用户上传的图像并将其放置在我的Content目录下。
但我担心会出现重复的情况,所以我想让它将图像上传为随机数。
以下是我的代码,您可以通过它理解我的意图。
<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);