好吧,我使用谷歌上发现的一个片段来获取用户上传的图像并将其放在我的目录下的内容下
好吧,这里是我的代码,你可以理解,无论如何我想通过它
<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
原文链接:https://www.f2er.com/php/135707.htmlhttp://php.net/manual/en/function.uniqid.php
$RandomAccountNumber = uniqid(); move_uploaded_file($ProfilePicTemp,"Content/" . $RandomAccountNumber);